How can I get the sender email address using Outlook.MailItem in VB.NET? -
How can I get the sender email address using Outlook.MailItem in VB.NET? -
i have tried using mailitem.senderemailaddress
, mailitem.sender.address
both homecoming string looks this:
/o=domainname/ou=exchange administrative grouping (fydibohi43spclt)/cn=recipients/cn=joe bloggs8c3
where in reality want joebloggs@domainname.co.uk
retrurned.
anyone have ideas?
thank much.
edit: have done digging; works email addresses of 'senderemailtype' smtp, doesn't work exchange email addresses.
edit 2: have tried code specified here, assume outdated because throws "cannot create active-x component" error.
edit 3: ever has same problem me, found reply (in c#, converted vb.net, still works though):
private function getsendersmtpaddress(mail outlook.mailitem) string dim pr_smtp_address string = "http://schemas.microsoft.com/mapi/proptag/0x39fe001e" if mail service nil throw new argumentnullexception() end if if mail.senderemailtype = "ex" dim sender outlook.addressentry = mail.sender if sender isnot nil 'now have addressentry representing sender if sender.addressentryusertype = outlook.oladdressentryusertype.olexchangeuseraddressentry orelse sender.addressentryusertype = outlook.oladdressentryusertype.olexchangeremoteuseraddressentry 'use exchangeuser object primarysmtpaddress dim exchuser outlook.exchangeuser = sender.getexchangeuser() if exchuser isnot nil homecoming exchuser.primarysmtpaddress else homecoming nil end if else homecoming trycast(sender.propertyaccessor.getproperty(pr_smtp_address), string) end if else homecoming nil end if else homecoming mail.senderemailaddress end if end function
i see have answered own question. post c# function here incase needs or if utilize more help. c# function doing looks this:
private string getsenderemailaddress(outlook.mailitem mail) { outlook.addressentry sender = mail.sender; string senderemailaddress = ""; if (sender.addressentryusertype == outlook.oladdressentryusertype.olexchangeuseraddressentry || sender.addressentryusertype == outlook.oladdressentryusertype.olexchangeremoteuseraddressentry) { outlook.exchangeuser exchuser = sender.getexchangeuser(); if (exchuser != null) { senderemailaddress = exchuser.primarysmtpaddress; } } else { senderemailaddress = mail.senderemailaddress; } homecoming senderemailaddress; }
vb.net email outlook outlook-addin mailitem
Comments
Post a Comment