In this step by step tutorial, we’ll explain how to save email message to disk in C#. The email message can be saved as EML or MSG file formats on the disk. We’ll be getting messages from Exchange email box, however you can get messages from other mail boxes as well and save to disk.
Steps to Save Email Message to Disk in C#
- Get Aspose.Email for .NET package from NuGet.org
- Include Aspose.Email.Clients.Exchange and Aspose.Email.Clients.Exchange.WebService namespaces
- Set license with the help of SetLicense method
- Provide Exchange Server account information
- Create an object of NetworkCredential class
- Create a new Exchange client object of EWSClient Class
- Loop through all the email messages read from the mail box
- Save each individual email message to EML or MSG file formats
By following the above simple steps, you can save email message to EML in C# code on the disk. In our previous topic, we explained how to send email in C# using Gmail SMTP server. However, in this topic, we’re using the Exchange server instead to fetch the emails and then save them to disk.
Code to Save Email Message to Disk in C#
In the above code, we’re saving email messages as .eml and .msg formats. Please note that in this code, we’re fetching all of the messages and saving them one by one in separate files. However, if your inbox has a lot of messages then you need to modify the approach accordingly.