DEV Community

Robin van der Knaap
Robin van der Knaap

Posted on • Originally published at Medium on

Create EML file from System.Net.Mail.MailMessage

For a project I was working on, I needed to create an EML file from the standard MailMessage class which exists in the System.Net.Mail namespace. I came across an article which describes how to extend the save functionality on the MailMessage class. Using the same technique I created an extension method which is able to save the MailMessage class as EML.

With this extension method in your solution you can create an EML file like this:

The extension method is implemented like this:

Conclusion

EML files are perfect for storing the email message on your file system or in the database. The EML file contains all the data from the email, including attachments. You can open the EML in most mail clients and view the email.

Latest comments (1)

Collapse
 
norm profile image
Norm • Edited

Thank you for this useful post.