Get attachment files from exchange emails in SSIS -
i have client send everyday email attachment files process it. have script task doesn't work, script connect account through webmail when script try read inbox folder error. in specific line: finditemsresults results = service.finditems(wellknownfoldername.inbox, querystring, view);
using system; using system.collections.generic; using system.linq; using system.threading.tasks; using system.windows.forms; using system.io; using microsoft.exchange.webservices.data; namespace testmailattachment { static class program { /// <summary> /// main entry point application. /// </summary> [stathread] static void main() { exchangeservice service = new exchangeservice(); service.credentials = new webcredentials("user", "pass", "domain"); /*service.url = new uri("https://webmail.domain.es/owa/");*/ service.autodiscoverurl("birep@domain.es"); getattachments(service); } private static void getattachments(exchangeservice service) { // return single item. itemview view = new itemview(1); string querystring = "hasattachments:true subject:'message attachments' kind:email"; //console.writeline("check test"); // find first email message in inbox has attachments. results in finditem operation call ews. finditemsresults<item> results = service.finditems(wellknownfoldername.inbox, querystring, view); if (results.totalcount > 0) { emailmessage email = results.items[0] emailmessage; // request attachments on email message. results in getitem operation call ews. email.load(new propertyset(emailmessageschema.attachments)); foreach (attachment attachment in email.attachments) { if (attachment fileattachment) { fileattachment fileattachment = attachment fileattachment; // load file attachment memory. gives access attachment content, // byte array can use attach file item. results in getattachment operation // call ews. fileattachment.load(); //console.writeline("load file attachment name = " + fileattachment.name); // load attachment contents file. results in getattachment operation call ews. fileattachment.load("\\\\server\\folder" + fileattachment.name); // put attachment contents stream. using (filestream thestream = new filestream("c:\\temp\\stream_" + fileattachment.name, filemode.openorcreate, fileaccess.readwrite)) { //this results in getattachment operation call ews. fileattachment.load(thestream); } } else // attachment item attachment. { itemattachment itemattachment = attachment itemattachment; // load item attachment properties. results in getattachment operation call ews. itemattachment.load(); //console.writeline("loaded item attachment subject = " + itemattachment.item.subject); } } } } } }
also don´t know how do, script take emails specific person or subject.
thanks in advance.
Comments
Post a Comment