none
Customized Email Body for Outlook RRS feed

  • Question

  • How can I design HTML based email body for Outlook, kindly just guide me that how can I add HTML code in VB code that and that code create body of Outlook email message.

    Or

    On other end, is there any possiblity that I use an HTML page saved in my computer as outlook email body, that when I click on command button using VB application, program call that particular HTML page (saved in my computer) and display it in Outlook email body.

    I want to use this HTML code or Call function for olMail.Body=

                ''''''''''''''''''' Start Outlook''''''''''''''''''
                ' If it is already running, you'll use the same instance...
                Dim olApp As Outlook.Application
                olApp = CreateObject("Outlook.Application")
    
                ' Logon. Doesn't hurt if you are already running and logged on...
                Dim olNs As Outlook.NameSpace
                olNs = olApp.GetNamespace("MAPI")
                olNs.Logon()
    
                ' Send a message to your new contact.
                Dim olMail As Outlook.MailItem
                olMail = olApp.CreateItem(Outlook.OlItemType.olMailItem)
                ' Fill out & send message...
                olMail.To = IU68_IL33_EvaluationsTableAdapter1.QuaryAgentEmail(ID)
                olMail.CC = IU68_IL33_EvaluationsTableAdapter1.QueryTLEmail(ID)
                olMail.Subject = "DiGi Evaluation"
    
                olMail.HTMLBody = ""
                olMail.Display()
    
                ' Clean up...
                'MsgBox("Emails sent successfully", MsgBoxStyle.Information, "Done")
                'olNs.Logoff()
                olNs = Nothing
                olMail = Nothing
                olApp = Nothing
                ''''''''''''''''''' End Outlook''''''''''''''''''
    

    Below is snapshot of HTML template that is saved in my compute and I want to call it in olMail.HTMLBody = ""


     

    Monday, November 28, 2011 5:11 PM

Answers

  • Hi anwar.mustafa,

     

    Thanks for posting in the MSDN Forum.

     

    Your snippet looks like a VBA application. I wrote a VBA snippet to support your goal. It works fine on my side (Windows 7, Outlook 2010)

    Sub ReadHTMLFileToMailBody()
        Dim objMailItem As Outlook.MailItem
        Dim objFileSystem As Object
        Dim objFileInfo As Object
        Dim objStream As Object
        Dim strSourceCode As String
        
        Set objMailItem = Application.CreateItem(olMailItem)
        Set objFileSystem = CreateObject("Scripting.FileSystemObject")
        Set objFileInfo = objFileSystem.GetFile("C:\***\***.html")
        Set objStream = objFileInfo.OpenAsTextStream(1, -2)
        strSourceCode = objStream.ReadAll
        objMailItem.HTMLBody = strSourceCode
        objMailItem.Display
        
        Set objMailItem = Nothing
        Set objStream = Nothing
        Set objFileInfo = Nothing
        Set objFileSystem = Nothing
    End Sub
    

     

     

     

    I hope it can help you.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Wednesday, November 30, 2011 6:28 AM
    Moderator

All replies

  • Hi anwar.mustafa,

     

    Thanks for posting in the MSDN Forum.

     

    Your snippet looks like a VBA application. I wrote a VBA snippet to support your goal. It works fine on my side (Windows 7, Outlook 2010)

    Sub ReadHTMLFileToMailBody()
        Dim objMailItem As Outlook.MailItem
        Dim objFileSystem As Object
        Dim objFileInfo As Object
        Dim objStream As Object
        Dim strSourceCode As String
        
        Set objMailItem = Application.CreateItem(olMailItem)
        Set objFileSystem = CreateObject("Scripting.FileSystemObject")
        Set objFileInfo = objFileSystem.GetFile("C:\***\***.html")
        Set objStream = objFileInfo.OpenAsTextStream(1, -2)
        strSourceCode = objStream.ReadAll
        objMailItem.HTMLBody = strSourceCode
        objMailItem.Display
        
        Set objMailItem = Nothing
        Set objStream = Nothing
        Set objFileInfo = Nothing
        Set objFileSystem = Nothing
    End Sub
    

     

     

     

    I hope it can help you.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Wednesday, November 30, 2011 6:28 AM
    Moderator
  • Hi Tom,

    Is it possible to compose email body message from outlook custom forms.

    Please let me know.

    Thank you

    Sri

    Tuesday, July 16, 2013 5:47 PM