Read emails from exchange

12 Jul 2022 146920 views 0 minutes to read Contributors

If you have challenges to write new code, SQLTreeo can help you writing code for you!

C# Source Code including code to save email attachments C# Source Code including code to save email attachments including (1 year Support + minor + major updates)
$49 one time purchase $98 one time purchase

Situation

You have an Office 365 mailbox. You want to use C# to read those mails and save them to SQLServer.

Requirements

  • Office365 mailbox
  • SQLServer
  • Exchange WebServices
  • C# (visual studio)

Exchange WebServices

Applies to: EWS Managed API | Exchange Online | Exchange Server 2013 | Office 365 There is 1 step you need to take and that is to install Exchange Webservices (MIT License). Download EWS Managed API via nuget. This step is very easy and does not require more then download/install via a nuget package. This only has to be done on your Development Machine. Once you want to release your product for production release all you need to include is the Microsoft.Exchange.WebServices.dll and you're all set.

Implemented Solution

 

Instantiate a new ExchangeService and provide your mailbox credentials.

Then, because you want to call an Webservice (ExchangeWebService EWS) you provide the webservice URL and you call the function FindItems( , ). This call will connect to your mailbox (if you've provided the correct credentials) and start reading (in this case 100 mail headers) After that you can read all the basic email properties like subject, from and to. Microsoft has implemented a lightweight EWS so that if you want to read more properties like Htmlbody or TextBody, you have to send an instruction to load that extra information with the following command:

Save your emails to the database

The complete visual studio solution & database table and procedure code can be downloaded after purchase.

SQLTreeo AiM Trial Download

About us

Over the years, SQLTreeo gained precious know-how which we transformed into customer support, managed database services and database solutions. In order to express our knowledge and experiences, we tend to work with anything less than the best-trained staff and that is the key to success and the biggest asset of our company. Thus, all our database management services are controlled by high level skilled and Senior database administrators. We can help you in every aspect of SQL Server.

 

Report a Bug

In this article