SPUtility.SendEmail inconsistent html format RRS feed

  • Question

  • Hi,

    I am trying to append html input to the string builder and send email to outlook. But I am not getting the format consistently all the time. Some times missing font color, some times bold and even some time am getting html text i.e. <td>... I have checked my complete input in different aspx pages and it loooks fine.  Same code i tried in a windows app and web app for testing and it works fine. But runtime while running on event handler, it is not generating the output consistently. Here is the part of my simple code. Am I missing anything?

    StringBuilder strBody = new StringBuilder();
    strBody.Append("<tr><td style=\"font-family:Arial;color:Red;font-style:italic;font-weight:bold;\">Contact</td></tr>");
    strBody.Append("<tr><td style=\"font-family:Arial;color:Black;\">Sample text......</td></tr>");

    StringDictionary mail = new StringDictionary();
    mail.Add("from", "");
    mail.Add("to", "ToAddress");
    mail.Add("subject", subject);
    mail.Add("content-type", "text/html");
    SPUtility.SendEmail(web, mail, strBody.ToString());

    Also tried this way but no luck....

    SPUtility.SendEmail(web,true,false,ToAddress,subject, strBody.ToString(),false);


    • Edited by ChicShare Sunday, March 4, 2012 4:47 AM
    Sunday, March 4, 2012 4:20 AM


All replies

  • Can you show the source of received letter? (view source in outlook)

    Also you can try to send email via System.Net.Mail namespace. My be problem in your smtp server...

    Monday, March 5, 2012 8:42 AM
  • Here is my one of email's view i observed that a character ismissing from html i.e. came as 'fnt-size' instead of 'font-size'. Randomly charactes also missing from the html input. It is very weird but I have no clue. Thanks.

    <tr><td style="padding-left:15px;width:100%;">
    <tr><td style="font-family:Arial;font-size:9pt;color:#3873A9; font-weight:bold;">Customer Info</td></tr>
    <tr><td style="font-family:Arial;font-size:9pt;color:Black; font-weight:bold;">Customer ID:</td><td><div style="font-family:Arial;font-size:9pt;color:Black;text-align:left;">12345</div></td></tr>
    <tr><td style="font-family:Arial;font-size:9pt;color:Black; font-weight:bold;">Customer Name:</td><td style="font-family:Arial;font-size:9pt;color:Black;text-align:left;">Name</td></tr>
    <tr><td style="font-family:Arial;font-size:9pt;color:Black; font-weight:bold;">Customer Location:</td><td style="font-family:Arial;font-size:9pt;color:Black;text-align:left;">City</td></tr>
    <tr><td style="font-family:Arial;font-size:9pt;color:Black; font-weight:bold;">Customer Joined Date:</td><td style="font-family:Arial;font-size:9pt;color:Black;text-align:left;">12/4/2011</td></tr>
    <tr><td style="font-family:Arial;font-size:9pt;color:Black; font-weight:bold;">Customer Expiration Date: </td><td style="font-family:Arial;font-size:9pt;color:Black;text-align:left;">3/4/2014</td></tr>



    <tr><td style="font-family:Arial;font-size:9pt;color:Black;">Customer Information Link: <a href="CustomerNamehttp://.....">CustomerName</a></td></tr>


    <table><tr><td style="font-family:Arial; fnt-size:9pt ;color:#3873A9;font-style:italic;font-weight:bold;">Support</td></tr>
    <tr><td style="font-family:Arial;font-size:9pt;color:Black;">Call support if you need any assistance.</td></tr>

    <tr><td style="font-family:Arial;font-size:9pt;color:Black;">Regards,</td></tr>
    <tr><td style="font-family:Arial;font-size:9pt;color:Black;">Tech Support</td></tr>

    • Edited by ChicShare Monday, March 5, 2012 3:41 PM
    Monday, March 5, 2012 3:40 PM
  • hi

    add logging to your event handler - write generated email body to some file (you may need to grant permissions to the account under which event handler is running to the folder which will contain log file). After that you will know is the problem in your code, or in Sharepoint or Outlook.

    Also try to open your emails in some other client, e.g. in some web client (you can send email to your gmail account temporary), and see how it will look like. Outlook 2010 inherited problems with html email from 2007 version which you may read e.g. here:

    Word 2007 HTML and CSS Rendering Capabilities in Outlook 2007 (Part 1 of 2)

    Word 2007 HTML and CSS Rendering Capabilities in Outlook 2007 (Part 2 of 2)

    Blog -
    CAML via C# -

    Monday, March 5, 2012 11:32 PM
  • Hi ChicShare,

    did you find out some reason - solution for that?

    I'm trying the same - send email using SPUtility. Send and getting the same:

    <td style="font-famiy:Verdana,Geneva,sans-serif;">
    missing l - family

    When I sent an email as plain text:
    SPUtility.SendEmail(web, true, true, toAddress, subject, message); 
    code looks fine (when copy paste to some html page)

    I also tried to send this email to my web email client, message looks same.

    What can causing this behavior?

    Thanks Jan
    • Edited by J.Homuta Friday, June 15, 2012 10:18 AM
    Friday, June 15, 2012 10:10 AM
  • hi Homuta

    I had the same problem that SPUtility.Send removes characters and screw up my html. 

    The solution I figured out is not use it. Use the following code instead (I am using it in timerjob, you need get SPWebApplication depend on where you are)

    SPWebApplication webapp = this.Parent as SPWebApplication;

    string outGoingMailServerAddress = webapp.OutboundMailServiceInstance.Parent.Name;
    string outGoingMailAddress = webapp.OutboundMailSenderAddress;


    MailMessage msgMail = new MailMessage();

                msgMail.To = toEmail;
                msgMail.From = outGoingMailAddress ;
                msgMail.Subject = subject;
                msgMail.BodyFormat = MailFormat.Html;
                msgMail.Body = mailBodyHtml;

        SmtpMail.SmtpServer = outGoingMailServerAddress;


    Wednesday, May 15, 2013 2:07 PM