Link to home
Start Free TrialLog in
Avatar of printmedia
printmedia

asked on

Load Outlook email template into vb.net Form

Hi all.

I'm trying to load an Outlook email template into a vb.net windows form so I can make some edits before sending it out from my windows form. I've done some reading and I saw a post where someone said to put it in a webBrowser control but when I do that I can not edit it. So then I saw some code where you can enable editing in the webBrowser control but my code below is not working.

Does anyone know how I can load an Outlook email template into a vb.net Windows form and be able to edit it before sending out from the same form (which I do now but without allowing the end user to edit the template). I started with a webBrowser control but I would try anything else (i.e. Rich Text Box etc.).

Thank you in advance!

Dim oApp As New Outlook.Application
        Dim mitem As Outlook.MailItem
        mitem = oApp.CreateItemFromTemplate("\\myServer\myapplicationfolder\EmailTemplate1.oft")
        WebBrowser1.DocumentText = mitem.HTMLBody
'Stopping here I am able to see the email template. But unable to do any edits.
'So I thought the code below would enable the edit

        Dim doc As IHTMLDocument2
        doc = DirectCast(WebBrowser1.Document.DomDocument, mshtml.IHTMLDocument2)
        doc.designMode = "On"
'Although it allows the webBrowser control to be edited, unfortunately, this code clears my original email template

Open in new window

Avatar of printmedia
printmedia

ASKER

I'm playing with the rich text box using the following code:

Dim oApp As New Outlook.Application
        Dim mitem As Outlook.MailItem
        mitem = oApp.CreateItemFromTemplate("\\myServer\myapplicationfolder\EmailTemplate1.oft")
RichTextBox1.Text = mitem.Body

Open in new window


But when I send out the email it's not formatted the same way as it is in the RichTextBox (i.e. the original Outlook email template)

Here's the code I use to send the email out from my vb.net application:

Dim oApp As Outlook.Application = CreateObject("Outlook.Application")
        oApp = New Outlook.Application()
        Dim signature As String

 Dim oMsg As Outlook._MailItem
        oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
 oMsg.Display()
        oMsg.To = txtEmailTo.Text
        oMsg.Subject = txtEmailSubject.Text

        signature = oMsg.HTMLBody
oMsg.HTMLBody = RichTextBox1.Text & vbCr & vbCr & signature

 oMsg.Send()
       
        oApp = Nothing
        oMsg = Nothing

Open in new window


Any tips on how I can make it send the email out with the proper formatting? I'm thinking somehow converting the RichTextBox text into HTML but I'm stuck.

It looks like I'm going to have to stick to the WebBrowser control because if the email template has font colors, underline or bold etc. it keeps it when I pull the webbrowser control text into the email as opposed to the richtextbox (I don't even see the different font color or if it's bolded or underlined).

Thank you in advance.
Avatar of Éric Moreau
Thank you for your reply. I'll give it try.
ASKER CERTIFIED SOLUTION
Avatar of printmedia
printmedia

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial