Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Retrieve senders email address from outlook

23 views
Skip to first unread message

Mark

unread,
Sep 2, 2003, 8:13:45 PM9/2/03
to
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 f...@bar.com 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 na...@org.com 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

Peter Huang [MSFT]

unread,
Sep 3, 2003, 2:09:06 AM9/3/03
to
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" <m...@yadayada.com>
>Sender: "Mark" <m...@yadayada.com>
>Subject: Retrieve senders email address from outlook
>Date: Tue, 2 Sep 2003 17:13:45 -0700
>Lines: 44
>Message-ID: <06f001c371b0$3d443990$a101...@phx.gbl>
>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

Peter Huang [MSFT]

unread,
Sep 3, 2003, 9:32:09 PM9/3/03
to
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: <06f001c371b0$3d443990$a101...@phx.gbl>
>MIME-Version: 1.0
>Content-Type: text/plain
>Content-Transfer-Encoding: 7bit
>From: v-ph...@online.microsoft.com (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: <G6aSvHec...@cpmsftngxa06.phx.gbl>
>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

Mark

unread,
Sep 3, 2003, 9:38:54 PM9/3/03
to
Hi Peter,

When I tried your suggestion I get the same address I got
when I queried using the reply object as shown in ex1
below. This appears to be a FirstNameLastName alias and
not the na...@location.com address that i need.

Is CDO a thin wrapper to the same code that Outlook uses?

Mark

>.
>

Peter Huang [MSFT]

unread,
Sep 4, 2003, 11:18:57 PM9/4/03
to
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.

--------------------
>Content-Class: urn:content-classes:message
>From: "Mark" <m...@yadayada.com>
>Sender: "Mark" <m...@yadayada.com>

>References: <06f001c371b0$3d443990$a101...@phx.gbl>
<G6aSvHec...@cpmsftngxa06.phx.gbl>
>Subject: RE: Retrieve senders email address from outlook
>Date: Wed, 3 Sep 2003 18:38:54 -0700
>Lines: 116
>Message-ID: <141501c37285$4cefd9f0$a501...@phx.gbl>


>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: AcNyhUzvOlzEX5sgQIOqLVCYcR41LQ==


>Newsgroups: microsoft.public.office.developer.automation
>Path: cpmsftngxa06.phx.gbl
>Xref: cpmsftngxa06.phx.gbl

microsoft.public.office.developer.automation:7280
>NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
>X-Tomcat-NG: microsoft.public.office.developer.automation

Mark

unread,
Sep 8, 2003, 2:07:51 PM9/8/03
to
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

>.
>

Peter Huang [MSFT]

unread,
Sep 9, 2003, 5:56:45 AM9/9/03
to
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" <m...@yadayada.com>
>Sender: "Mark" <m...@yadayada.com>

>References: <06f001c371b0$3d443990$a101...@phx.gbl>
<G6aSvHec...@cpmsftngxa06.phx.gbl>
<bg#CcRocD...@cpmsftngxa06.phx.gbl>


>Subject: RE: Retrieve senders email address from outlook

>Date: Mon, 8 Sep 2003 11:07:51 -0700
>Lines: 178
>Message-ID: <3d0301c37634$1e8fe6b0$a301...@phx.gbl>


>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

0 new messages