none
HTMLBody font different in code than user RRS feed

  • Question

  • I have written some code that places a simple text only, no formatting codes string into the HTMLBody of the messageItem.  When the message is displayed, I get a TimesNewRoman 12pt font.  If I the user open an email and type the text I get a Calibri 10pnt font.

    In addition, when I exported the email to HTML to view its codes, it states the format for sections of my signature to be TimesNewRoman, which is different than the display which is Calibri (as saved in the signature editor).

    <p style='margin-right:.5in'><span style='<span style='"Times New Roman"; color:#1F497D;This is a transmission from

    If everything is supposed to default to Calibri, and I didn't set any font changes, then why the difference?


    Jamie V Johnson

    • Moved by Weiwei Cai Thursday, September 1, 2016 2:07 AM more related to Outlook for developer
    Tuesday, August 30, 2016 4:10 PM

All replies

  • Update, If I put a character return "<br>" infront of the body string, it formats the entire body as one font, (the default font).  Its my workaround for now, but that means all my emails will have a blank line at top.

    Jamie V Johnson

    Tuesday, August 30, 2016 4:41 PM
  • Hi Jamie,

    Do you use any third part control to display your email content in your Silverlight application? I suggest you upload a sample project to OneDrive and share a public link here, which can help us reproduce this issue in my side.

    Please try use encoding and decoding when you display the email content and export the content to make sure the email content string are not changed.

    Best Regards,
    Weiwei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, August 31, 2016 5:09 AM
  • Ok this is strange.  First of all, I placed this thread specifically in the MS Office interop form.  Second, it 'third party' program is MS Outlook 2016 that is giving me this behavior while utilizing the standard MS Word 2016 for email rendering.  As for the code its nothing special:

        Public Sub StartEmail(strTo As String, strSubject As String, strBody As String)
            Dim sb As New System.Text.StringBuilder
            If String.IsNullOrWhiteSpace(strTo) Then
                Dim sec As TTSMainDataCore.Security = TTSMainDataCore.Security.Instance
                Dim rowContact As TTSMainDataCore.TTSMainDataSet.ContactsRow = TTSMainDataCore.TTSDataCore.Instance.Contacts.FindByID(sec.UserContactID)
                If Not rowContact.IsEmailNull Then
                    If String.IsNullOrWhiteSpace(strTo) Then strTo = rowContact.Email
                    If Not String.IsNullOrWhiteSpace(strTo) Then
                        Dim outlook As Microsoft.Office.Interop.Outlook.Application = GetOutLook()
                        Dim mailItem As Microsoft.Office.Interop.Outlook.MailItem = outlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
                        mailItem.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML
                        mailItem.Display()
                        Dim strSignature As String = mailItem.HTMLBody
                        mailItem.To = strTo
                        mailItem.Subject = strSubject
                        mailItem.HTMLBody = "<br>" & strBody & "<br>" & strSignature
                    End If
                End If
            End If
        End Sub
    
        Private OutLookApp As Microsoft.Office.Interop.Outlook.Application
    
        Function GetOutLook() As Microsoft.Office.Interop.Outlook.Application
            Dim application As Microsoft.Office.Interop.Outlook.Application
            'Check if there is an Outlook process running.
            If Process.GetProcessesByName("OUTLOOK").Count() > 0 Then
                ' If so, use the GetActiveObject method to obtain the process and cast it to an Application object.
                application = DirectCast(Marshal.GetActiveObject("Outlook.Application"), Microsoft.Office.Interop.Outlook.Application)
            Else
                ' If not, create a new instance of Outlook and log on to the default profile.
                application = New Microsoft.Office.Interop.Outlook.Application()
            End If
            ' Return the Outlook Application object.
            Return application
        End Function
    Still shouldn't get such strange behavior.


    Jamie V Johnson

    Wednesday, August 31, 2016 2:26 PM
  • Hi Jamie,

    This forum is discuss around authoring Silverlight .NET applications.

    According to your description and sample code, your issue is more related to Outlook development. I help you move this thread to Outlook for developers forum to get better help. Thanks for your understanding.

    Best Regards,
    Weiwei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Weiwei Cai Thursday, September 1, 2016 2:06 AM
    Thursday, September 1, 2016 2:05 AM
  • Hi Jamie,

    >>it 'third party' program is MS Outlook 2016 that is giving me this behavior while utilizing the standard MS Word 2016 for email rendering. 

    What do you mean? Could you share us detailed steps? I made a test with below code in a simple console application. It works correctly at my side. It outputs the Calibri font.

        Public Sub StartEmail(strTo As String, strSubject As String, strBody As String)
            Dim sb As New System.Text.StringBuilder
    
            Dim outlook As Microsoft.Office.Interop.Outlook.Application = GetOutLook()
                Dim mailItem As Microsoft.Office.Interop.Outlook.MailItem = outlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
                mailItem.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML
                mailItem.Display()
                Dim strSignature As String = mailItem.HTMLBody
                mailItem.To = strTo
                mailItem.Subject = strSubject
                mailItem.HTMLBody = "<br>" & strBody & "<br>" & strSignature
                mailItem.Display()
    
        End Sub

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, September 2, 2016 9:51 AM
  •                 Dim strPackageName As String = piPackage.ItemName & "-" & piPackage.Revision
                    Dim strSubject As String = "Drawing Package Released:  " & strPackageName
                    Dim strEmailBody As String = "The email is to notify you of the release of " & strPackageName &
                        ".  It is for [Package Description]." & "<br>" & "<br>" & "This revision includes: (if any)" & "<br>" & "<br>" &
                        "It can be accessed through the database and includes:" & "<br>" &
                        "•	Bundled drawing package" & "<br>" &
                        "•	Individual Files" & "<br>" &
                        "•	DXF files (if any)" & "<br>" &
                        "•	Other Documents (if any)" & "<br>" & "<br>" &
                        "Please inquire with the project lead for any questions or concerns.  Thanks."
                    Tools.StartEmail(String.Empty, strSubject, strEmailBody)
    That's pretty much the code.  When I added the "<br>" on the mailitem.HTMLBody line infront of strBody, it started formatting everything as Calibri, but if you take out that first "<br>" then it messed things up using the Times new roman font.  It's baffling for sure, because I don't know where the use of that font got introduced in my system, a template, default setting?  Nothing pans out.

    Jamie V Johnson

    Friday, September 2, 2016 2:05 PM
  • Hi Jamie,

    Thanks for more information, and I could reproduce your issue by removing “<br>”.

    To be honesty, I have checked the related settings, but I failed to find the root cause. To work around this issue, I would suggest you add font style in html. Something like below:

    " <font face='Calibri (Body)' size='5'>Bedrock</font>"

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, September 5, 2016 3:13 AM
  • Hi I know this is an old post, but I had the same issue while working with excel vba to send to outlook.

    I was able to use the <p> tag instead of <br> to get it to work like you were trying to Jamie.  Note: I did not close my code with a </P> later on either.

    Cheers

    Friday, September 7, 2018 7:36 AM