none
Set Font Style and Size of email message called from VB.net RRS feed

  • Question

  • Hello,

    I am calling an email object from my VB.NET program, and setting a textbox contents as the message body, and this works great.  However, I would like to set the Font Style and Size for the message body but not having much luck.  This is simple text, so I don't want to do anything fancy like HTML formatting.  Here is my current code:

        Public Sub EmailOrder()
    
            Dim item As Outlook.MailItem
            item = olApp.CreateItem(Outlook.OlItemType.olMailItem)
            item.Subject = "BUILD ORDER CONFIRMATION"
            item.Body = txtOrderPrint.Text
            item.Display()
    
        End Sub

    I call this sub from a command button, and like I said, it works great. I just want to set a standard font "Courier" and size 12 so that regardless of user or email settings the text will remain consistent.

    Any help appreciated.

    TIA,

    ColtsFanMN

    Monday, December 8, 2014 8:53 PM

Answers

  • Hello,

    The Body property of Outlook items doesn't contain any formatting. You need to use the HTMLBody property for setting the HTML markup or the WordEditor property of the Inspector class which returns an instance of the Word document. Outlook uses Word as an email editor. Thus, you can use the Word object model to modify the body according to your needs.

    You can read more about possible ways in the Chapter 17: Working with Item Bodies.

    Monday, December 8, 2014 9:29 PM

All replies

  • Hello,

    The Body property of Outlook items doesn't contain any formatting. You need to use the HTMLBody property for setting the HTML markup or the WordEditor property of the Inspector class which returns an instance of the Word document. Outlook uses Word as an email editor. Thus, you can use the Word object model to modify the body according to your needs.

    You can read more about possible ways in the Chapter 17: Working with Item Bodies.

    Monday, December 8, 2014 9:29 PM
  • Hi ColtsFanMN,

    The suggestion provided by Eugene is helpful and correct, if the issule still remained please try the code below:

     item.HTMLBody = "<span style='font-size:12.0pt;font-family:""Courier New"" '>Hello Word!</span>"

    Regards & Fei


    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.

    Tuesday, December 16, 2014 11:14 AM
    Moderator
  • Hi ColtsFanMN,

    The code works well for me. Did it work for you? If not, please share the detail about the issue so that we can help fix this issue.

    Regards & Fei


    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, December 17, 2014 1:57 AM
    Moderator
  • Fei,

    As stated in the original post, I don't want to use HTML.

    Thanks.

    Wednesday, December 17, 2014 1:41 PM
  • Hi ColtsFanMN,

    Thanks for the clarification.

    Microsoft Outlook provides three body text format options: Plain Text, Rich Text (RTF), and HTML. And as Eugene stated that we also could use WordEditor to insert and format text.

    Here is an sample using it to achive the goal for your reference:

    Dim aMailItem As MailItem
    Set aMailItem = Application.ActiveInspector.CurrentItem
    
     Application.ActiveInspector.WordEditor.Application.Selection.Font.Name = "Courier New"
     Application.ActiveInspector.WordEditor.Application.Selection.Font.Size = 12
     Application.ActiveInspector.WordEditor.Application.Selection.TypeText Text:="Hello Word!"
    Regards & Fei


    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.

    Thursday, December 18, 2014 2:07 AM
    Moderator
  • Hello,    (I am also in MN)

    I was attempting to overcome a vb.net Outlook Template shortcoming, where my salutation and body, which are added to variable separately, come out as different fonts and sizes for some reason.

    I used the span tags above, but switched to Calibri. It worked great... sort of. It does make uniform the font, but the size is still stuck at size 10, which comes through pretty small in email. I wonder what I am doing wrong.

    Here is what I used: 

    .HTMLBody = "<span style='font-size:12.0pt;font-family:""Calibri"" '>" & stHTMLBody & "</span>"


    Thanks...


    Friday, February 12, 2016 10:27 PM
  • Just in case someone else is having the same issue... I was stuck at size 11 until I stopped trying to set size 12 (12.0px, not 12.0pt, maybt thats your fault) and set it to 11.5 or 12.5, all sizes worked except 12.0, don't know why... so I ended using 11.5.

    PD: My font was Courier New.

    Monday, May 28, 2018 10:32 AM