I am using below code to read incoming mails from MS Outlook 2010 -
public static void outLookApp_NewMailEx(string EntryIDCollection)
{
The address returned now is an (X.400) Exchange address. Please take a look at this MSDN article on how to retrieve the corresponding SMTP address.
I am using this VBA routine to retrieve the SMTP
address of a mailItem
object:
(should be easily portable to C#)
Private Function getSmtpMailAddress(sMail As Outlook.mailItem) As String
Dim strAddress As String
Dim strEntryId As String
Dim objRecipient As Outlook.Recipient
Dim objSession As Outlook.NameSpace
Dim objAddressentry As Outlook.AddressEntry
Dim objExchangeUser As Outlook.ExchangeUser
Dim objReply As Outlook.mailItem
On Error GoTo ErrHandler
If sMail.SenderEmailType = "SMTP" Then
strAddress = sMail.SenderEmailAddress
Else
Set objReply = sMail.reply()
Set objRecipient = objReply.recipients.item(1)
strEntryId = objRecipient.EntryID
objReply.Close OlInspectorClose.olDiscard
Set objSession = getMapiSession
strEntryId = objRecipient.EntryID
Set objAddressentry = objSession.GetAddressEntryFromID(strEntryId)
Set objExchangeUser = objAddressentry.GetExchangeUser()
strAddress = objExchangeUser.PrimarySmtpAddress()
End If
getSmtpMailAddress = strAddress
Exit Function
ErrHandler:
Err.Clear
On Error GoTo 0
getSmtpMailAddress = "???"
End Function
This works for Outlook 2007
. The MSDN
solution for Outlook 2010 as pointed out above, looks a bit nicer.