Total Pageviews

Search This Blog

Saturday, December 11, 2010

How to Read email and download attachment from AX (AOS) without Installing Outlook Client and using EWS Exchange Web Services

Design Requirement

To meet one of our solution requirement, we had to built an interface in AX which should be able to read an email with a particular subject line and download the invoice attachment to do further processing and posting of the same.

I searched on the web and most of the existing solutions or blog posts are about AX Sending emails where AX Communicates to Microsoft Exchange Server and is tightly coupled with Outlook client to be installed on AOS or client.

In our server topology, our infrastructure/IT team at the client's place won't allow us to install any office tools on the server, thereby ruling out the option of installing Outlook Client on the server.


After some research, I found that EWS is the way to go. EWS stands for Exchange Web Services which is an extensible component for clients to connect to your Exchange Server and can read emails from a particular mailbox. Here are the steps:

a. Download EWS SDK by going to this url,
Note, we have a separate SDK for EWS 2010. I downloaded the above SDK as our client is still on Exchange Server 2007

b. Install the Exchange Service msi which copies the Exchange Web Service dll to C:\Program Files\Microsoft\Exchange folder

c. Retrieve this dll and copy to your assembly on the AOS Server. i.e. you can drag and drop this dll file into C:\Windows\assembly

d. Note that this assembly is a .Net assembly so for me the easiest way was to write a custom wrapper assembly in C# which consumes the Microsoft Exchange Web Service (i.e. the dll in step b)

e. Add this custom dll into your References node in AOT

f. Write a class in AX which invokes your custom assembly

g. In my scenario, all the code had to achieve is given the parameters of email id, subject and UNC path name (Network location), it looks up the Exchange Store, reads the email with that particular subject line and downloads the related invoice attachment and strips it to the folder location on the network

And all this achieved without any mess and just few lines of code. If anybody interested in code, feel free to write to me and I can send you the .cs file

Happy Dax'ing :)


Anonymous said...

Hi Dilip, I'm interested in your example .cs code. ;-)
Can you please mail me that?

greetz Geert (geert[@]

Steeve G said...

Very interresting! I though about this some time but never knew how to read email from code. Can you send me the .cs file? Thanks!

Sandip Jadhav said...

May I have C# code ?


Abdul Samad Patel said...

Can I kindly have the code?

hans said...

Hi Dilip,

I'm also interested in the code. Can you send it to

Thank you,

Shafiq said...

Hi Dilip,

Could you please send me the .cs code, I needed some help on this.

Thanks & Regards,

Shafiq Hussain

Anonymous said...

Hi Dilip,

I'm very much interested in the .cs code. Can you email me that one? And I have a question. Is it possible to update tasks / contactpersons via this method?

Thanks a lot!


Marchel (

shivraj said...

Hi Dilip, can you please send me the .cs code?


tobias.brueggendick said...

Hi Dilip,

can you please mail me the C# Code (

Thanks in Advance and Best Regards,

Anonymous said...

Hello Dilip,

Even we have a requirement where we need to download a pdf file from outlook email to a shared drive. Can u pls send the code ?

I never used Microsift dynamics. Do u think I need a microsoft dynamics expert to do this set-up or any dummy can do this code?

shan (

Ykke said...

Hi Dilip,
i'm intrested in the example code

Anonymous said...

Hi Dilip,

This is great, can i get this .cs file please..

my email

Anonymous said...

Can I get the Code please

PepeSifuentes said...

Hello, can I havethe code as well?

Anonymous said...

Hi Dilip, I'm interested in your example .cs code.
Can you please mail me that?

Luiz (

Muhammad Amir said...

Hi Can you also please send this code to me ?


Hi Dilip,

I am having a AX 2012 Customization where i need to read an attachment in the email and load data into AX tables. Please send your code to my mail id : for my reference.

Thanks in advance
Bharat V

Anonymous said...

Hi Dilip, would you send me the .cs and any code you can share with it? Thanks a lot



Kapil Mansukhani said...
This comment has been removed by the author.
Anonymous said...


Can you please send me the .cs file?

Thank you!

Anonymous said...

I'd live your example code also. My email is

Forever Sang Ram said...

why dont disclose you the code?

panliner shipping

panliner shipping said...

pls disclose the code

panliner shipping said...

send me the code.

Sergey Dolgov said...

Hi, Dilip!
I have been looking for such opportunity for several days! Would you be so kind to send me the code?
My email is

Thank you in advance.

Margus said...

Hi, Dilip!

Very interesting! I have been looking for such opportunity for several weeks!
Could you please send me the code?
My email is

Thank you in advance.

Haroon Attari said...

Can I have the code please.
haroon [dot] attari [at] gmail [dot] com

Abdullah Agha said...

Hi, Dilip,

Your post is really appreciated. I need your code. My email address is


Abdullah Agha said...

Hi, dilip! really appreciate your post kindly send me the code. Email:

Abdullah Agha said...

Send me code. email: