Retrieve senders email address from outlook

M

Mark

I have automated Outlook from both VB and C# but I am
having confusion with what should be a very simple
operation.

I cannot find a property that returns a consistently
useful and complete email address for the message sender.

From the MailItem object you can only get the sender's
name.

If I create a reply and look at the recipient address or
the address associated with recipient.AddressEntry they
both agree with one another but the address isn't always
in the (e-mail address removed) representation.

In the case of exchange originated email the
inconsistancies go so far as having multiple
representations for different messages originating from
the same organization:

ex1:
addEntry Address: /o=EXCHORG/ou=First
Administrative Group/cn=Recipients/cn=FirstNameLastName

ex2:
addEntry Address: /o=EXCHORG/ou=First
Administrative Group/cn=Recipients/cn=FirstName@bar

SMTP mail that i've checked does seem to be in the
traditional (e-mail address removed) format but is it always so?

Finally, if I call AddressEntry.Details on the reply's
recipient (the original sender) the dialog that is
displayed contains a tab that has a list of name:value
pairs that describe the valid mail transports and their
associated email addresses.

This is the information that i really want access to. How
do I access this list? What am I missing that is making
this so hard?

Thanks

Mark
 
P

Peter Huang [MSFT]

Hi Mark,

You may try to use the Microsoft CDO Library. I have tested on a mail from
outsource.

Private Sub Command1_Click()
Dim olapp As New Outlook.Application
Dim mitem As MailItem
Set mitem =
olapp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("test").I
tems(1)
Dim msg As MAPI.Message
Dim s As New MAPI.Session
s.Logon "outlook", , False
Set msg = s.GetMessage(mitem.EntryID)
MsgBox msg.Sender.Address
s.Logoff
End Sub

I will research the issue and will update you with new information as soon
as possible.



Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
 
P

Peter Huang [MSFT]

Hi Mark,
Is CDO a thin wrapper to the same code that Outlook uses?
No, CDO means Collaboration Data Objects, and it can work without outlook
supported.

You refer the link below for more information.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncdo121/ht
ml/collabdataobjs.asp

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
 
M

Mark

Hi Peter,

I wanted to let you know the results of the tests
performed with the code from your link.

In VB you can do the following:


' undocumented property value
Const g_PR_SMTP_ADDRESS_W = &H39FE001F

Dim msg As MAPI.Message
Dim mapi As New MAPI.Session
Dim senderEmailAddress As String

mapi.Logon("outlook", , False)
senderEmailAddress = msg.Sender.Fields
(g_PR_SMTP_ADDRESS_W).value

I could not make this work in c# because the Sender object
does not expose a Fields property.

Can you provide a sample of how to make this call in c# so
that the results are the same as in the VB code?

Thanks

Mark
-----Original Message-----
Hi Mark,

I have found a helpful KB link. It works with Exchange User on OutlookXP
2002
http://support.microsoft.com/default.aspx?scid=kb;EN- US;324530
You may have a test and let me know the result.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
X-Tomcat-ID: 137008001
References: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: (e-mail address removed) (Peter Huang [MSFT])
Organization: Microsoft
Date: Wed, 03 Sep 2003 06:09:06 GMT
Subject: RE: Retrieve senders email address from outlook
X-Tomcat-NG: microsoft.public.office.developer.automation
Message-ID: <[email protected]>
Newsgroups: microsoft.public.office.developer.automation
Lines: 77
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.office.developer.automation:7274
NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122

Hi Mark,

You may try to use the Microsoft CDO Library. I have tested on a mail from
outsource.

Private Sub Command1_Click()
Dim olapp As New Outlook.Application
Dim mitem As MailItem
Set mitem =
olapp.GetNamespace("MAPI").GetDefaultFolder
(olFolderInbox).Folders("test").
I
tems(1)
Dim msg As MAPI.Message
Dim s As New MAPI.Session
s.Logon "outlook", , False
Set msg = s.GetMessage(mitem.EntryID)
MsgBox msg.Sender.Address
s.Logoff
End Sub

I will research the issue and will update you with new information as soon
as possible.



Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

.
 
P

Peter Huang [MSFT]

Hi Mark,

Since C# is a strong type language. So it must provide all parameters to
invoke a member.
Here I write a sample for you.

using System;
using System.Reflection;
namespace ConsoleApplication9
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
MAPI.Session ms = new MAPI.SessionClass();
MAPI.Messages mms;
MAPI.Message mm;
string strAddress;
const int g_PR_SMTP_ADDRESS_W = 0x39FE001F;
object[] os = new object[7];
object o = Missing.Value;
os[3]=false;
ms.Logon(o,o,o,false,o,o,o);
MAPI.Folder ib = (MAPI.Folder)ms.Inbox;
mms=(MAPI.Messages)ib.Messages;
for(int i=1;i<=(int)mms.Count ;i++)
{
mm=(MAPI.Message)mms.get_Item(i);
MAPI.Fields oFields=(MAPI.Fields)((MAPI.AddressEntry)mm.Sender).Fields;
int count = (int)oFields.Count;
MAPI.Field fd =(MAPI.Field)oFields.get_Item(count,g_PR_SMTP_ADDRESS_W);
strAddress = fd.Value.ToString();
for(int j=count-1;j>0;j--)
{
if (strAddress.IndexOf('@',0,strAddress.Length)!=-1)
{
break;
}
fd =(MAPI.Field)oFields.get_Item(j,g_PR_SMTP_ADDRESS_W);
strAddress = fd.Value.ToString();
}
Console.WriteLine(strAddress);
}
ms.Logoff();
}
}
}

Since C# is a strong typed language, the count parameter can not be omitted
just like you do in VB or VB.NET.
MAPI.Field fd =(MAPI.Field)oFields.get_Item(count,g_PR_SMTP_ADDRESS_W);
So I think you may need to evaluate all the items in the fields to get the
correct item.
If possible, you may use VB.NET, it is similar with VB.

Did this answer your question?

Here is KB link.
Support Policy for Microsoft Exchange APIs with .NET Framework Applications
http://support.microsoft.com/default.aspx?scid=kb;en-us;813349

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
Content-Class: urn:content-classes:message
From: "Mark" <[email protected]>
Sender: "Mark" <[email protected]>
References: <[email protected]>
Subject: RE: Retrieve senders email address from outlook
Date: Mon, 8 Sep 2003 11:07:51 -0700
Lines: 178
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcN2NB6PI0ls5SFkRXah5HJtiZ7Sbw==
Newsgroups: microsoft.public.office.developer.automation
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.office.developer.automation:7310
NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
X-Tomcat-NG: microsoft.public.office.developer.automation

Hi Peter,

I wanted to let you know the results of the tests
performed with the code from your link.

In VB you can do the following:


' undocumented property value
Const g_PR_SMTP_ADDRESS_W = &H39FE001F

Dim msg As MAPI.Message
Dim mapi As New MAPI.Session
Dim senderEmailAddress As String

mapi.Logon("outlook", , False)
senderEmailAddress = msg.Sender.Fields
(g_PR_SMTP_ADDRESS_W).value

I could not make this work in c# because the Sender object
does not expose a Fields property.

Can you provide a sample of how to make this call in c# so
that the results are the same as in the VB code?

Thanks

Mark
-----Original Message-----
Hi Mark,

I have found a helpful KB link. It works with Exchange User on OutlookXP
2002
http://support.microsoft.com/default.aspx?scid=kb;EN- US;324530
You may have a test and let me know the result.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
X-Tomcat-ID: 137008001
References: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: (e-mail address removed) (Peter Huang [MSFT])
Organization: Microsoft
Date: Wed, 03 Sep 2003 06:09:06 GMT
Subject: RE: Retrieve senders email address from outlook
X-Tomcat-NG: microsoft.public.office.developer.automation
Message-ID: <[email protected]>
Newsgroups: microsoft.public.office.developer.automation
Lines: 77
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.office.developer.automation:7274
NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122

Hi Mark,

You may try to use the Microsoft CDO Library. I have tested on a mail from
outsource.

Private Sub Command1_Click()
Dim olapp As New Outlook.Application
Dim mitem As MailItem
Set mitem =
olapp.GetNamespace("MAPI").GetDefaultFolder
(olFolderInbox).Folders("test").
I
tems(1)
Dim msg As MAPI.Message
Dim s As New MAPI.Session
s.Logon "outlook", , False
Set msg = s.GetMessage(mitem.EntryID)
MsgBox msg.Sender.Address
s.Logoff
End Sub

I will research the issue and will update you with new information as soon
as possible.



Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
Content-Class: urn:content-classes:message
From: "Mark" <[email protected]>
Sender: "Mark" <[email protected]>
Subject: Retrieve senders email address from outlook
Date: Tue, 2 Sep 2003 17:13:45 -0700
Lines: 44
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Thread-Index: AcNxsD1Ely5aFiQXSeenBvZEUgMyrw==
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Newsgroups: microsoft.public.office.developer.automation
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl
microsoft.public.office.developer.automation:7272
NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
X-Tomcat-NG: microsoft.public.office.developer.automation

I have automated Outlook from both VB and C# but I am
having confusion with what should be a very simple
operation.

I cannot find a property that returns a consistently
useful and complete email address for the message sender.

From the MailItem object you can only get the sender's
name.

If I create a reply and look at the recipient address or
the address associated with recipient.AddressEntry they
both agree with one another but the address isn't always
in the (e-mail address removed) representation.

In the case of exchange originated email the
inconsistancies go so far as having multiple
representations for different messages originating from
the same organization:

ex1:
addEntry Address: /o=EXCHORG/ou=First
Administrative Group/cn=Recipients/cn=FirstNameLastName

ex2:
addEntry Address: /o=EXCHORG/ou=First
Administrative Group/cn=Recipients/cn=FirstName@bar

SMTP mail that i've checked does seem to be in the
traditional (e-mail address removed) format but is it always so?

Finally, if I call AddressEntry.Details on the reply's
recipient (the original sender) the dialog that is
displayed contains a tab that has a list of name:value
pairs that describe the valid mail transports and their
associated email addresses.

This is the information that i really want access to. How
do I access this list? What am I missing that is making
this so hard?

Thanks

Mark

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top