Solved

How do I insert HTML code to Outlook AppointmentItem body

Posted on 2009-05-04
2
2,836 Views
Last Modified: 2012-05-06
Is there any way I can insert HTML formatted code inside AppointmentItem body?
Currently I'm using C# to edit HTMLBody on MailItem, but I couldn't find a HTMLBody on AppointmentItem.
Or is there any workaound to do this? e.g. using the AppointmentItem's word editor?


Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application();
 

AppointmentItem objApp = (AppointmentItem)outlookApp.CreateItem(OlItemType.olAppointmentItem);
 

objApp.Subject = "the title";
 

objApp.Location = "the location";
 

// Appointment will display this as plain string, while I want it to be in html format

objApp.Body = "<html><title>the title</title><body><p>the content goes here</p></body></html>";
 

objApp.Start = DateTime.Now;
 

objApp.Save();

Open in new window

0
Comment
Question by:AdviceExpert
2 Comments
 

Accepted Solution

by:
texas_tl earned 125 total points
ID: 24341973
Outlook does not provide a command to insert tables or other complex elements into HTML messages, nor does it give you a way to edit the source of an HTML message. The View Source command that you see on the right-click context menu in an HTML message does not let you save any changes to the source back into the message. There are several ways to compose complex HTML messages, though.
Method 1: One approach is to create the HTML content using your favorite HTML editor. Save it as an .htm file, and then use one of these methods to get it into the Outlook message:

Check Tools, Options, Mail Format to make sure Outlook is set to use HTML as its default message format. In Internet Explorer, browse to the HTML page that you saved as a file. Then, choose File | Send | Page by Email.

Or, in Outlook itself, make sure that WordMail as your editor is turned off and use the Web toolbar in Outlook 2000 or the Address box in Outlook 2002 to navigate to the web page. Then, choose Actions | Send Web Page by E-mail. (Thanks to Margaret Blauvelt for this tip.)

Create a new HTML-format Outlook message. In Internet Explorer, browse to the HTML page that you saved as a file. Choose Edit | Select All, then Edit | Copy. Switch to the Outlook message and paste the copied material into the body of the message.

Create a new HTML-format Outlook message. Choose Insert | File and select the saved HTML file. At the bottom right corner of the Insert File dialog, click the small arrow next to the Insert button, and choose Insert as Text.

Method 2: Another way to create an HTML message with really rich HTML tags is to use Microsoft Word to create the document, then choose File | Send To | Mail Recipient. This adds To, Cc, and Subject boxes to the top of the Word window, where you can fill in the recipient address and subject. When you send the message, Word uses HTML format. Unfortunately, in Word 2000, it also bloats the message with several KB of Office-specific XML formatting information. Word 2002, on the other hand, provides a way to strip the XML. You'll find this Filter HTML before sending option in Word 2002 under Tools | Options | General | E-mail Options, on the General tab.

Method 3: Outlook 2002 provides yet another method: Simply use Word as your e-mail editor (Tools | Options | Mail Format). WordMail in Office XP is much better than in previous versions. You can use all the Word composition tools and choose whether to send the message in plain text, HTML or RTF format.

With WordMail as your editor, you can also edit the HTML source directly if you have the Web Scripting component from Office XP installed. You must add the HTML Source command to your toolbar (View | Toolbars | Customize). Normally, Word does not display this command unless you are editing an .htm file. I have tried this method only in Office XP, but it might also work in Office 2000.

Method 4: Use code to create an Outlook MailItem object (objMsg in the snippet below), then use FileSystemObject methods to read the contents of a saved .htm file:

Set fso = CreateObject("Scripting.FileSystemObject")

Set ts = fso.OpenTextFile("c:\testfile.htm", _

  ForReading)

strText = ts.ReadAll

objMsg.HTMLBody = strText

Method 5: Create a new document in Microsoft FrontPage, then use FrontPage's File | Send command. (We tried this in Office XP, but not Office 2000 yet.) The resulting message will include an extraneous two line feeds and horizontal line at the top, but you can easily delete these. This method preserves internal bookmarks. (Thanks to Stephen Green for this tip.)

Be careful with your <img> tags if you use this method, because the message always uses the exact tag from your document, even if you have Outlook set to embed images in outgoing HTML messages. Therefore, the <img> tags will need to point to files available on the Internet. This, in turn, may annoy people who use dial-up Internet connections, since Outlook will try to connect to try to display the images when the recipient opens or previews the message.


Source: http://www.slipstick.com/mail1/html.htm
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Get an idea of what you should include in an email disclaimer with these Top 5 email disclaimer tips.
Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now