Link to home
Start Free TrialLog in
Avatar of RobHortn
RobHortn

asked on

Use .NET or SSIS to download Exhange email and process attachments

I thought this would be fairly straightforward but the rope is fraying fast on this one.

We have clients who send us email on a daily basis, emails containing attachments.  These attachments need to be automagically downloaded from Exchange and then imported to our database.

Does anybody out there know if there is a programmatic way to access an Exhange mailbox, loop through all messages, and download the attachments to a file share?

Thanks in advance for any help/advice on this one!
Avatar of Stacy Spear
Stacy Spear
Flag of United States of America image

Are stuck on the entire thing or just a portion of it?
Avatar of RobHortn
RobHortn

ASKER

Pretty much the entire thing.  I think if I can just figure out how to connect to a single Exchange mailbox I can noodle out the rest though.
Avatar of Reza Rad
does exchange mailboxes in sql server database? or in file system?
and what is the structure of data there?
As far as I know Exchange is set up to use the file system.  I don't know the structure of the data there, sorry.
Connecting to the database itself is bad. I'll send some code later. Should be some to Google some as well.
It is possible to use SSIS , when there are files in directory or subdirectory when structure of all files are same.
you just need to loop through files , this can be done with Foreach Loop Container and set enumerator as file enumerator,
and then inside the foreach loop combination of script task, file system task and data flow task, will help you on transfer data.

this was whole schema, but if you need detailed explanation please provide sample file of exchange system and tell me how you want to transfer to destination ?
Does the machine running the tool have Outlook on it? This will be vastly easier if it does.
@darkstar3d - yes i think it does have Outlook on it.  Does that mean I'm stuck with using CDO to access the mailbox then?
I think I may have found an answer to this.  Has anyone ever heard of "Redemption" as a way to read mail via .NET?
http://it.toolbox.com/blogs/programming-life/reading-email-using-mapi-in-vbnet-5855
So my basic scenario is this.  Emails come into certain accounts, I need to strip the attachements from them on a schedule, dump them to certain folders, and then import them into our database via SSIS.
What I think I will do is:
  • Write an outside program, named say, ProcessIt, this will basicall be the outside container app, running on a schedule, that will pull the emails down from their mailboxes and write them out to the file server.  The email accounts, security and such will be database driven, as well as where the files will be dropped.
  • ProcessIt, at the end of its .. um .. processing, will then kick off the SSIS package that will loop through all those directories and import each file therein.
Anybody see any flaws in this plan?  As I understand it, when accessing mail via CDO like this, and using Redemption to avoid the security prompts, you can pull mail using any computer that has the security information for the Exchange account.
I think this model will work unless I'm missing something obvious.  What say you all?
Sorry, was out on a staycation.

That looks to be the plan. I have never used Redemption and I don't think you get a warning unless you are accessing email addresses. I will try it out a bit latter. Also, using Outlook is MAPI. Direct access is usually CDO. CDO requires more code and is legacy while Outlook may change, but is still current.
Since posting this earlier today, I'm finding it's difficult to even read mail, even via Outlook anymore.  It seems Microsoft only wants us to send it.  I'm a bit lost and frustrated with this.  Seems that CDO is no longer supported and with the newer version of Outlook 2007, not even included.
Does anyone know if there is a way in Exchange perhaps to set up rules or something that will auto-save the attachments as they come in?
ASKER CERTIFIED SOLUTION
Avatar of RobHortn
RobHortn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial