Save email body with HTML tags?


Hi I am trying to save body of an email to a file and want to keep html tags, however all I can get is plain text. I have tried save mail message and write text to file mail.Body with with mail.IsBodyHtml = True. Your help is much appreciated. I would like to get Content-Type: text/html but I am only getting : Content-Type: text/plain;

Get Outlook Mail Message not working

Hi Gary_k

Mail Message list collection consists following headers with indexs.
Indexes are:
0 - Uid
1 - Date
2 - DateCreated
3 - DateRecieved
4 - HtmlBody
5 - Size

testtt(Autosaved).xaml (6.1 KB)

I have attached a demo workflow edit Get Outlook mail messages activity properties before to use.



That doesn’t actually answer the question (and is a copy-paste from a different topic - please link instead).

Text/html versions of email can be usually retrieved from alternateViews (as streams).
A very basic example attached.
For production usage at least encoding should also be checked (see SO examples)

EmailHtmlRead.xaml (13.4 KB)


Hey @andrzej.kniola

what is invoke method here and doing what in above context? will you please explain?




Invoke Method there is used to call a void Dispose() on the reader object.
Since workflows work on activities, if you don’t have an activity for a void method (void meaning it doesn’t return anything), you need to use Invoke Method for it.

For methods that have a return value InvokeMethod is not needed, because they’re usually used in right side of assign, as an If condition etc.

Calling the Dispose on a stream (or actually any IDisposable) is a good practice. Some would even say a mandatory requirement.
Since there’s no explicit Using scope, calling Dispose manually is the third best thing we can do (like I said, this was a very basic example and I put the Dispose there more from habit then anything else :slight_smile: ).

Second best would be to wrap it in TryCatch and in Finally clause do an if(reader!=null) reader.Dispose(). That way we could guarantee that the object gets freed even if there were exceptions.

If you don’t Dispose of an object, it will get disposed by the Garbage Collector at some point, but that’s undeterministic - until that happens, if we’d be operating on a file, that file would be considered used by the operating system until the stream would release the handle to it.

This may lead to unexpected errors like reading a file, doing some in-memory processing and having an error while trying to write the changes back, because the file is still considered used.

I’d recommend starting here on MSDN for understanding Dispose pattern and researching further if needed.