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.

Solution

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 http://www.microsoft.com/downloads/en/details.aspx?FamilyId=190F71A4-7B5F-4A4C-99BA-9BD032E16E15&displaylang=en,
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 :)

30 comments:

Anonymous said...

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

greetz Geert (geert[@]pulse.nl)

Steeve Gilbert 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...

Dilip,
May I have C# code ?

Thanks
Sandip

Abdul said...

Can I kindly have the code?

Anonymous said...

Hi Dilip,

I'm also interested in the code. Can you send it to mohamed.tassisto@student.artesis.be

Thank you,
M. TASSISTO

Unknown said...

Hi Dilip,

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


Thanks & Regards,

Shafiq Hussain

shafiqhussain@hotmail.com

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!

Greetings,

Marchel (mdleeuw@yahoo.com)

Unknown said...

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

Thanks
-Shiv

tobias.brueggendick said...

Hi Dilip,

can you please mail me the C# Code (tob@seelhof.de)?

Thanks in Advance and Best Regards,
Tobias

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?

thanks,
shan (sshanbh@yahoo.com)

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 khalid_akkawi@windowslive.com

Anonymous said...

Can I get the Code please
gus@kanimambo.com.au

PepeSifuentes said...

Hello, can I havethe code as well?
Thanks.

pepesifuentes@Hotmail.com

Anonymous said...

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

Luiz (ltartarotti@gmail.com)

Muhammad Amir said...

Hi Can you also please send this code to me ?

Bharat Venkatraman said...

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 : bharatvenkatraman@gmail.com 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

Stefan

stefan.kale[@]polysol.com

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

Hi!

Can you please send me the .cs file?

Thank you!

willardalec@yahoo.com

Anonymous said...

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

Anonymous said...

why dont disclose you the code?

regards,
panliner shipping

panliner shipping said...

pls disclose the code

panliner shipping said...

send me the code.

Unknown 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 farvex@gmail.com

Thank you in advance.
Sergey.

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 margus023@gmail.com

Thank you in advance.
Margus.

Haroon said...

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

Anonymous said...

Hi, Dilip,

Your post is really appreciated. I need your code. My email address is abdullahagha@hotmail.com

Regards,
Abdullah.

Anonymous said...

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

Anonymous said...

Send me code. email: abdullahagha@hotmail.com