C# - Read emails from exchange online mailbox (Office 365) into SQL Server
20 Aug 2020 6754 views 0 minutes to read Contributors
You have an Office 365 mailbox. You want to use C# to read those mails and save them to SQLServer.
C# (visual studio)
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.
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:
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.