Importing Emails
The MailMessage class, can Import Email in three different formats which are mentioned below.
- Microsoft Outlook Email Message Format (Msg).
- Microsoft Html Format (Mht).
- RFC 822 Compliant Message Format (Eml).
Steps to Import Email in different formats
To import email in different formats, follow the steps given below:
- Create an instance of MailMessage class.
- Load an email in the instance of MailMessage class by specifying the file name and Message Format in MessageFormat class.
Import Email in Microsoft Outlook Message Format
In the code given below, we have imported an email message in Microsoft Outlook Message Format.
[C#]
//Create an instance of MailMessage class
MailMessage msg = new MailMessage();
//Import an Outlook file
msg = MailMessage.Load(@"e:\test.msg", MessageFormat.Msg);
[VB.NET]
'Create an instance of MailMessage class
Dim msg As MailMessage = New MailMessage()
'Import an Outlook file
msg = MailMessage.Load("e:\test.msg", MessageFormat.Msg)
Import Email in Eml Format
In the code given below, we have imported an email message in RFC 822 Compliant Message Format.
[C#]
//Import from eml format
msg = MailMessage.Load(@"e:\test.eml", MessageFormat.Eml);
[VB.NET]
'Import an Eml file
msg = MailMessage.Load("e:\test.eml", MessageFormat.Eml)
Import Email in Mht Format
In the code given below, we have imported an email message in Microsoft Html Format.
[C#]
// Load Mht file
msg = MailMessage.Load(@"e:\test.mht", MessageFormat.Mht);
[VB.NET]
'Load Mht file
msg = MailMessage.Load("e:\test.Mht", MessageFormat.Mht)
Conclusion
There are many components in the market that allow parsing emails in different formats like RFC 822 Compliant Message Format (Eml) and Microsoft Html Format (Mht) but Aspose.Network is the first .NET component in the market that also allows developers to parse Microsoft Outlook Email Message Format (Msg) that gives a competitive advantage to Aspose.Network on its competitors.
Exporting Emails
The MailMessage class can export email in two different formats as mentioned below.
- RFC 822 Compliant Message Format (Eml).
- Microsoft Html Format (Mht).
Steps to Export an Email in different formats
To export an email in different formats, follow the steps given below:
- Create an instance of MailMessage class.
- Save email message by specifying the file path and message format in MessageFormat class instance.
Export Email in Mht Format
[C#]
//Create an instance of MailMessage class
MailMessage msg = new MailMessage();
//Export in Mht format
msg.Save(@"e:\test.mht", MessageFormat.Mht);
[VB.NET]
'Create an instance of MailMessage class
Dim msg As MailMessage = New MailMessage()
'Export in Mht format
msg.Save("e:\test.mht", MessageFormat.Mht)
Export Email in Eml Format
[C#]
//Export an Eml file
msg.Save(@"e:\test.eml", MessageFormat.Eml);
[VB.NET]
'Export an Eml file
msg.Save("e:\test.eml", MessageFormat.Eml)
The above code snippet produces an exported email message in Eml format as shown below:
Figure: An Exported email message in Eml format.