MsgConvert Class
Provides methods for parsing and converting Outlook .MSG files/streams (in OLE2 format) into MailMessage objects and files/streams in .EML format (RFC822 MIME), and for building .MSG files/streams from MailMessage objects and .EML files/streams.
Inheritance Hierarchy
SystemObject
  MailBee.OutlookMsgConvert

Namespace: MailBee.Outlook
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
public class MsgConvert

The MsgConvert type exposes the following members.

Constructors
  NameDescription
Public methodMsgConvert
Creates an instance of MsgConvert class.
Public methodMsgConvert(String)
Creates and unlocks an instance of MsgConvert class.
Top
Methods
  NameDescription
Public methodEmlToMsg(Stream, Stream)
Converts .EML data (in RFC822 text format) into a stream in Outlook .MSG (OLE2) format with 8-bit encoding.
Public methodCode exampleEmlToMsg(String, String)
Converts .EML data (in RFC822 text format) into a file in Outlook .MSG (OLE2) format with 8-bit encoding.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodMailMessageToMsg(MailMessage, Stream)
Saves the specified MailMessage into a stream in Outlook .MSG (OLE2) format.
Public methodMailMessageToMsg(MailMessage, String)
Saves the specified MailMessage as Outlook .MSG file.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodMsgToEml(Stream, Stream)
Converts Outlook .MSG data (in OLE2 binary format) into .EML data (in RFC822 MIME format).
Public methodCode exampleMsgToEml(String, String)
Converts Outlook .MSG file (in OLE2 binary format) into .EML file (in RFC822 MIME format).
Public methodCode exampleMsgToMailMessage(Stream)
Parses Outlook .MSG data stream into MailMessage object.
Public methodMsgToMailMessage(String)
Parses Outlook .MSG file into MailMessage object.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Properties
  NameDescription
Public propertyHtmlToRtfMethod
Gets or sets which HTML-to-RTF conversion method to use when making .MSG out of .EML source.
Public propertyStatic memberLicenseKey Obsolete.
Assigns the license key.
Public propertyMsgAsDraft
Gets or sets whether the resulting .MSG message should be saved as "Draft" (editable) or "Sent" (read-only).
Public propertyMsgAsUnicode
Gets or sets whether string values during .EML-to-.MSG transformation will be saved as Unicode (allows using international characters).
Public propertyMsgIsFromMe
Gets or sets whether MSGFLAG_FROMME flag will set in the resuling .MSG message.
Public propertyOnByteToStringConversion
Gets or sets the application-supplied callback MailBee will execute in order to convert bytes to string when making .EML from .MSG source.
Public propertyOnHtmlToRtfConversion
Gets or sets the application-supplied callback MailBee will execute in order to convert HTML-to-RTF when making .MSG out of .EML source.
Public propertyPreferAddressesFromInternetHeaders
Gets or sets whether From/To/CC/BCC addresses must be loaded from Internet headers of the .MSG message.
Public propertyPreferRtfBodyToHtml
Gets or sets whether the HTML body of the resulting .EML should be taken from RTF part (instead of HTML part) of the source .MSG message, if it has both RTF and HTML part.
Public propertyCode exampleRtfInEmlMethod
Gets or sets if RTF text body from .MSG message should be added as an attachment or as a body part into the resulting .EML message, or not added at all.
Public propertyTrialDaysLeft
Gets the number of days left to the date of the trial license key expiration.
Top
Remarks
You can perform the following operations using this class:
  • Convert a .EML (MIME) source from a file, stream or MailMessage object into Outlook .MSG stream or file
  • Convert an Outlook .MSG file or stream into MailMessage object or .EML (MIME) file or stream
  • Select whether to use ANSI or Unicode encoding for produced Outlook .MSG data
  • Save Outlook .MSG data as Draft or read-only items
  • Perform simple conversion of HTML into RTF when converting .EML into .MSG, or use an external high-quality HTML-to-RTF converter supplied by your application
  • Select whether (and how) to store RTF data in the .EML output when converting .MSG data into .EML data
  • Extract HTML body from .MSG source during .MSG to .EML conversion (if the source contains such body)

Prior to creating instances of this class, the correct license key must be set. See MailBee.Global.LicenseKey property for details.

Note Note
This class can only deal with OLE2 .MSG files. XML mail messages (can be created by Outlook 2007 and higher) are not supported.
Examples
This sample converts .MSG file into MailMessage object and then saves the resulting converted message to .EML file. It's assumed MailBee.Global.LicenseKey is already assigned (for instance, in app.config or web.config file).
Note Note
This sample shows how to use streams and MailMessage objects within the conversion (this also allows you to modify the resulting mail message prior to saving it into a file. If you only need to convert .MSG file into .EML (or vice versa), you can simply use MsgToEml(String, String) or EmlToMsg(String, String) methods.
// To use the code below, import these namespaces at the top of your code.
using System.IO;
using MailBee.Outlook;
using MailBee.Mime;

// The actual code (put it into a method of your class).
FileStream fs = new FileStream(@"C:\Mail\test.msg", FileMode.Open);
MsgConvert conv = new MsgConvert();
MailMessage msg = conv.MsgToMailMessage(fs);
fs.Close();
msg.SaveMessage(@"C:\Mail\test.eml");
See Also