c# - Outlook - Find email of account the message was sent to -


my client has problem , mean have problem:

in case email recipient have multiple emails configured in outlook - have 1 yahoo email account , 2 exchange accounts different exchange servers.

when processing incoming email in processitemadd event handler (add-in express) try discover account out of 3 email sent to:

so first method is:

                         outlook.mailitem re = ((outlook._mailitem)mail).reply();                         if (re != null)                         {                             var thisemail = "";                             outlook.account account = re.sendusingaccount;                             if (account != null)                             {                                 thisemail = account.smtpaddress;                                 log.verboseformat("thisemail = {0}", thisemail);                                  marshal.releasecomobject(re);                                 re = null;                                  marshal.releasecomobject(account);                                 account = null; 

it works on machine outlook 2010 32bit, not work on client machine outlook 2010, returning empty string. second (backup method) is:

                                if (string.isnullorempty(thisemail))                                 {                                     // requires in case of exchange account should cached exchange account.                                     thisemail = (string)mail.propertyaccessor.getproperty("http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-c000-000000000046}/8580001f");                                     log.verboseformat("got receiver account email address schema: {0}", thisemail);                                 }                             }                         } 

again works on machine not work on client machine, returning empty string. did verify in client's case sender exchange account caching...

btw, works fine on client machines when sender non-exchange , receiver exchange account...

is there other method reliably can determine account email sent (in case of multiple recipients).

here latest code works on 2010/2013 not on 2007. on latter account null , x-header returned empty:

                            outlook.mailitem re = ((outlook._mailitem)mail).reply();                         if (re != null)                         {                             var thisemail = "";                             outlook.account account = re.sendusingaccount;                             if (account != null)                             {                                 thisemail = account.smtpaddress;                                 log.verboseformat("thisemail = {0}", thisemail);                                  marshal.releasecomobject(re);                                 re = null;                                  marshal.releasecomobject(account);                                 account = null;                                 if (string.isnullorempty(thisemail))                                 {                                     string x_headers = (string)mail.propertyaccessor.getproperty("http://schemas.microsoft.com/mapi/proptag/0x007d001f");                                     thisemail = findtargetemail(x_headers);                                     log.verbose("extracted target email address mime x-headers: {0}", thisemail);                                  }                              }                             else                              {                                 log.verbose("account null...");                                  if (string.isnullorempty(thisemail))                                 {                                     string x_headers = (string)mail.propertyaccessor.getproperty("http://schemas.microsoft.com/mapi/proptag/0x007d001f");                                     thisemail = findtargetemail(x_headers);                                     log.verbose("extracted target email address mime x-headers: {0}", thisemail);                                 }                              }  

edit: well, not on yet. although works on machines have client reports problem on 2010. strange problem. user user1@domain1.com (cached exchange account) sends email user user2@domain2.com (gmail account). when parse mime header on receiver side above code in order address email sent to...i user1@domain1.com instead of user2@domain2.com !! how possible? know parsing right part of header (do ?) , on machines returns correct result...why not happen on of client's machines??

experts, ideas?

typically store in outlook profile represents separate account. may handle itemadd event of items class (processitemadd in adx terms) in each store identify account email message sent to.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -