I am developing the addin for the outlook 2007 using VSTO. One of the function is to capture the send event, then force convert the email format to HTML and then insert a link to the bottom of the email message content. Following is my code to convert the email content to html format:
mailItem.BodyFormat = OlBodyFormat.olFormatHTML;
string link = generateLink();
mailItem.Body += link;
However, when the email was recevied, it is not appear in the HTML format
What's wrong with the above code for making email as HTML?
Thank ~~
Patrick
You have to set mailItem.HTMLBody instead of mailItem.Body to use HTML.
Related
I'd like to use an MS Word template to format emails for a mail merge. I currently use MS Access / VBA / MS Outlook to generate emails, but all of the formatting I'm looking for I hardcode (e.g. {b}, {i}, {u}, {br /}, etc.) Is there a way to use an existing MS Word template to create the body of my email, and allow me to enter data in merge fields.
I don't know how to integrate an MS Word template into my VBA code to generate emails in MS Outlook.
You can save a draft email with placeholders as a template on the disk. When required, you can create a new item based on the Outlook template item and then replace placeholders in the message body with the data required. Use the HTMLBody property of Outlook items which represents the message body.
Read more about that in the article which I wrote for the technical blog - How To: Create a new Outlook message based on a template.
You can also save a html page/template in a richtext memo field and use the replace() function to fill your merge fields, no ms word needed.
I am trying to replace specific text in an email (skype meeting invite) with a custom piece of text that is a URL. I can do this fine for plain text via a vba macro in outlook click to run (2016/2019), but if I run the below against the expected html email that the meetings create it breaks the formatting completely.
Sub ChangeS4bMeeting()
Application.ActiveInspector.CurrentItem.body = Replace(Application.ActiveInspector.CurrentItem.body, "Conference ID: ", "https://linkhere")
End Sub
It ends up replacing the text correctly and adding what follows that space after the colon to the replaced text as the URL, but formatting of the whole invite email breaks.
I have tried using "HTMLBody" value instead of "body" value but this fails to run at all as it breaks on that line. Any ideas? Would it also be possible to have this run automatically when I selected New Items > Skype Meeting in outlook rather than running the macro manually (or have the macro include the creation of a skype meeting directly)?
Thanks in advance!
You must ensure that the content placed in the HTMLBody is properly formatted and that any such text is placed between the and tags in the HTMLBody.
For more information, please see the following link:Find and Replace as a VBA Macro
You can create custom rules that execute scripts to implement specific conditions for executing the script.
please see the following link: Create a Custom Rule executing a Script
Some people advice that it is good idea to sent an e-mail in both format html and plain text together in the same e-mail body as following link explains.
https://litmus.com/blog/reach-more-people-and-improve-your-spam-score-why-multi-part-email-is-important
You can see four code options below.
.BodyFormat = Outlook.OlBodyFormat.olFormatHTML
.BodyFormat = Outlook.OlBodyFormat.olFormatPlain
.BodyFormat = Outlook.OlBodyFormat.olFormatRichText
.BodyFormat = Outlook.OlBodyFormat.olFormatUnspecified
You are able to select one option as following picture shows.
http://www.rocketseed.com/wp-content/uploads/2013/07/Outlook-2010-HTML.jpg
How to sent mixed formatted e-mails even your code must include one option?
I need vb.net code for this.
That link does not apply to Outlook: when a message is saved (or sent) all 3 flavors of the message body (plain, HTML, RTF) are synchronized. You cannot send a message from Outlook with either flavor out of sync. You can send plain text messages, html/plain, or RTF (winmail.dat), but you cannot send with plain text body out of sync of the HTML body.
I need to send text from Excel textbox with HTMLBODY. So when i send it as
.HTMLBody = ThisWorkbook.Worksheets("info").Shapes("TextBox 1").TextFrame2.TextRange.Characters.Text
Email comes without formating.
So how to convert textbox to Html source? Or how to get data from html file to .HTMLBody?
Ron de Bruin's website has some great stuff on sending HTML emails. Look on this page for the RangetoHTML function.
Each Outlook 2007 RSS item (MessageClass = "IPM.Post.Rss") has View article... URL. How to extract that? I think I can extract that from objItem.HTMLBody or from objItem.Body by parsing the text. But looks like it is incorrect approach - it will not work with non-Eng versions of Outlook. Also, it will not work properly if there is another link with the same text.
Is there any other way to get this URL?
Here is the answer:
url = Item.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/id/{00062041-0000-0000-C000-000000000046}/8901001F")