locked
Sending in HTML format from VB.Net 2010 through Outlook RRS feed

  • Question

  • I am currently sending e-mail from a VB.Net 2010 app through Outlook using the below code:

     

      Public Sub SendOutlookMail(ByVal Subject As String, ByVal Recipient As _
      String, ByVal Message As String, ByVal Originator As String, ByVal CC As String)
    
        On Error GoTo errorHandler
        Dim oLapp As Object
        Dim oItem As Object
    
        oLapp = CreateObject("Outlook.application")
        oItem = oLapp.createitem(0)
        '
        With oItem
          .Subject = Subject
          .SentOnBehalfOfName = Originator
          .To = Recipient
          .body = Message
          .CC = CC
          .Send()
        End With
        '
        oLapp = Nothing
        oItem = Nothing
        '
    
        Exit Sub
    
    errorHandler:
        oLapp = Nothing
        oItem = Nothing
        ErrorState = True
        MessageBox.Show("Notification failed; check that all addresses/entries are valid and try again.", "Task failure (Outlook).", MessageBoxButtons.OK, MessageBoxIcon.Stop)
        Exit Sub
      End Sub
    


    These e-mails go out as plaintext; I would like to send them in HTML format.  I form up the content in another sub elsewhere in the app.  What would I need to do to get these into HTML format?  Simply use <HTML> ... </HTML> or...?

    -JNJ

    Monday, August 1, 2011 6:19 PM

Answers

  • HTMLBody is the property where you would write HTML content, if you write it to Body it will always be plain text.
     
    The HTML must be properly formatted. The easiest way to see how to do that is to review the HTMLBody property in an HTML format email.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "GotVBQuestions" <=?utf-8?B?R290VkJRdWVzdGlvbnM=?=> wrote in message news:ef8e2734-bd7a-4672-a6e4-995c60fac15a...

    I am currently sending e-mail from a VB.Net 2010 app through Outlook using the below code:

     

     Public Sub SendOutlookMail(ByVal Subject As String, ByVal Recipient As _
     String, ByVal Message As String, ByVal Originator As String, ByVal CC As String)
    
      On Error GoTo errorHandler
      Dim oLapp As Object
      Dim oItem As Object
    
      oLapp = CreateObject("Outlook.application")
      oItem = oLapp.createitem(0)
      '
      With oItem
       .Subject = Subject
       .SentOnBehalfOfName = Originator
       .To = Recipient
       .body = Message
       .CC = CC
       .Send()
      End With
      '
      oLapp = Nothing
      oItem = Nothing
      '
    
      Exit Sub
    
    errorHandler:
      oLapp = Nothing
      oItem = Nothing
      ErrorState = True
      MessageBox.Show("Notification failed; check that all addresses/entries are valid and try again.", "Task failure (Outlook).", MessageBoxButtons.OK, MessageBoxIcon.Stop)
      Exit Sub
     End Sub
    


    These e-mails go out as plaintext; I would like to send them in HTML format.  I form up the content in another sub elsewhere in the app.  What would I need to do to get these into HTML format?  Simply use <HTML> ... </HTML> or...?

    -JNJ


    Ken Slovak MVP - Outlook
    • Marked as answer by GotVBQuestions Wednesday, August 3, 2011 9:28 PM
    Monday, August 1, 2011 7:34 PM

All replies

  • HTMLBody is the property where you would write HTML content, if you write it to Body it will always be plain text.
     
    The HTML must be properly formatted. The easiest way to see how to do that is to review the HTMLBody property in an HTML format email.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "GotVBQuestions" <=?utf-8?B?R290VkJRdWVzdGlvbnM=?=> wrote in message news:ef8e2734-bd7a-4672-a6e4-995c60fac15a...

    I am currently sending e-mail from a VB.Net 2010 app through Outlook using the below code:

     

     Public Sub SendOutlookMail(ByVal Subject As String, ByVal Recipient As _
     String, ByVal Message As String, ByVal Originator As String, ByVal CC As String)
    
      On Error GoTo errorHandler
      Dim oLapp As Object
      Dim oItem As Object
    
      oLapp = CreateObject("Outlook.application")
      oItem = oLapp.createitem(0)
      '
      With oItem
       .Subject = Subject
       .SentOnBehalfOfName = Originator
       .To = Recipient
       .body = Message
       .CC = CC
       .Send()
      End With
      '
      oLapp = Nothing
      oItem = Nothing
      '
    
      Exit Sub
    
    errorHandler:
      oLapp = Nothing
      oItem = Nothing
      ErrorState = True
      MessageBox.Show("Notification failed; check that all addresses/entries are valid and try again.", "Task failure (Outlook).", MessageBoxButtons.OK, MessageBoxIcon.Stop)
      Exit Sub
     End Sub
    


    These e-mails go out as plaintext; I would like to send them in HTML format.  I form up the content in another sub elsewhere in the app.  What would I need to do to get these into HTML format?  Simply use <HTML> ... </HTML> or...?

    -JNJ


    Ken Slovak MVP - Outlook
    • Marked as answer by GotVBQuestions Wednesday, August 3, 2011 9:28 PM
    Monday, August 1, 2011 7:34 PM
  • HTMLBody is the property where you would write HTML content, if you write it to Body it will always be plain text.
      
    The HTML must be properly formatted. The easiest way to see how to do that is to review the HTMLBody property in an HTML format email.


    Got it - thnx.  Do you have a reference/resource 
     you could point me to that explains what's allowed/not allowed?
    Tuesday, August 2, 2011 1:34 AM
  • See if the information at http://www.slipstick.com/mail1/html.htm helps.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "GotVBQuestions" <=?utf-8?B?R290VkJRdWVzdGlvbnM=?=> wrote in message news:2fee45f3-af8b-480e-8dcd-99ce9c7aaf1a...
    HTMLBody is the property where you would write HTML content, if you write it to Body it will always be plain text.
      
    The HTML must be properly formatted. The easiest way to see how to do that is to review the HTMLBody property in an HTML format email.


    Got it - thnx.  Do you have a reference/resource 
     you could point me to that explains what's allowed/not allowed?

    Ken Slovak MVP - Outlook
    Tuesday, August 2, 2011 1:45 PM