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!
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
maybe use a different method. Have you tried https://www.codeproject.com/Articles/17561/Programmatically-adding-attachments-to-emails-in-C
ASKER
Thank you for your reply. I'll give it try.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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:
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.