MickyMc
asked on
Extract Attachment from Exchange server in C# VS 2008
Hi there,
this sounds simple, but after googling to much my head has gone google.
I need to write a service that will scan an email box for new emails and pull out the attachments. The I will unzip them and process them. Sounds simple.
I have use .net to send emails but never to attach to an inbox and check for emails.
What is the simplest and easy way to do this... bearing in mind that the email account will be in my organisation that uses Outlook. I have seen some people use 3rd party POP3 libaries etc but surely this can be done by straight forward .net libaries.
I was going to test this by connecting to my own account and testing so any sample code on this would be great.
Much appreciated.. mick
this sounds simple, but after googling to much my head has gone google.
I need to write a service that will scan an email box for new emails and pull out the attachments. The I will unzip them and process them. Sounds simple.
I have use .net to send emails but never to attach to an inbox and check for emails.
What is the simplest and easy way to do this... bearing in mind that the email account will be in my organisation that uses Outlook. I have seen some people use 3rd party POP3 libaries etc but surely this can be done by straight forward .net libaries.
I was going to test this by connecting to my own account and testing so any sample code on this would be great.
Much appreciated.. mick
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK so it seems that when you iterate through the MailItems there can be Calendar items in your inbox and when you try to cast them... Exception.
Instead you have to iteratie through all the items and try and cast them to an Mail Item.
So back to the question ... is this the best approach
Instead you have to iteratie through all the items and try and cast them to an Mail Item.
So back to the question ... is this the best approach
if you are using Exchange 2007 & 2010, the the EWS API is quite easy to use. http://msdn.microsoft.com/en-us/library/dd637749(EXCHG.80).aspx
ASKER
robberbaron, you could be on the money here. This actually looks good. My only beef is that I cant see how I can specify an email server and login details. I used Interop.Outlook and found that it takes the creditentials from the client Outlook on my destop and just ignores the login creditentials in the api. I took emoreau advice and used http://www.lesnikowski.com/mail/ which is a great little application for the price. I could specify the server and get different users to login into their accounts and pull back the emails. However I'm not sure if my company will allow 3rd party controls to be used other than Microsoft.
So if you can let me know if this supports connections to various exchange servers with differential creditals the points are yours..
So if you can let me know if this supports connections to various exchange servers with differential creditals the points are yours..
what do you want to do exactly? if you login using different credentials, yes you will be able to access what those credentials gives you access to.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks Gents, I'm splitting the points as both answers where of great help so it comes down to a matter of preference. Thanks for all your help...
regards Mick
regards Mick
ASKER
I put some code together and just curious why you dont use the Interop.Outlook like below
Open in new window
I'm just reading through my outlook inbox and putting the results in a grid. However I get an exception on this for loop..
Open in new window
It tells me invalid cast... but it works for most mails and only throws an exception on some... any ideas