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

MailItem Sender email address

1,096 views
Skip to first unread message

MJ

unread,
Feb 19, 2003, 12:27:55 AM2/19/03
to
If I have a MailItem, how do I get the sender's email
address? The only property I see is the Sender property
and that just gives me the friendly name. I want the
email address.

Alternately, how would you get the message headers? I
don't see a property for that either.

Thanks.

Hans Börjesson

unread,
Feb 19, 2003, 1:52:26 AM2/19/03
to
You can fake a reply and grab the sender address.

Set Reply = CurrentMail.Reply
Reply.Recipients will include sender email address.

There are other ways if you use advanced MAPI. You can read my question
dated 2003-01-28 in this newsgroup and read answers there.


Regards
/Hans Börjesson

Sue Mosher [MVP]

unread,
Feb 19, 2003, 7:34:19 AM2/19/03
to
There is no Outlook property that returns the sender's email address. You can either use CDO (or Redemption to avoid security prompts -- http://www.dimastr.com/redemption/) to get the From address or use Outlook to get the Reply To address, as Hans suggested. Sample code at http://www.slipstick.com/dev/code/getsenderaddy.htm.

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm


"MJ" <jaco...@yahoo.com> wrote in message news:004501c2d7d7$a7bdf5e0$2f01...@phx.gbl...

MJ

unread,
Feb 19, 2003, 4:08:59 PM2/19/03
to
I would think there's got to be another way. From what I
understand you have to specifically install CDO, yet
inside outlook, there appears to be no problem returning
the senders email address or internet headers. Yet
another undocumented API?

I'm trying to do this on a box unattached to an exchange
server (getting internet mail only) and nothing extra
(like CDO installed).

Is there a way to get the Message Headers? Maybe using
some MAPI API?

Any other ideas?

Thanks.

>.
>

Sue Mosher [MVP]

unread,
Feb 19, 2003, 4:47:59 PM2/19/03
to
Same thing: To access the message headers, you must use CDO or Redemption or, in C++ or Delphi, Extended MAPI.

You did see, didn't you, that you can easily get the reply address with Outlook objects only? That's more relevant than the actual From address in many cases.

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm


"MJ" <jaco...@yahoo.com> wrote in message news:01a501c2d85b$1ef85550$a401...@phx.gbl...


> I would think there's got to be another way. From what I
> understand you have to specifically install CDO, yet
> inside outlook, there appears to be no problem returning
> the senders email address or internet headers. Yet
> another undocumented API?
>
> I'm trying to do this on a box unattached to an exchange
> server (getting internet mail only) and nothing extra
> (like CDO installed).
>
> Is there a way to get the Message Headers? Maybe using
> some MAPI API?
>
> Any other ideas?
>
> Thanks.
>
> >-----Original Message-----
> >There is no Outlook property that returns the sender's
> email address. You can either use CDO (or Redemption to
> avoid security prompts --
> http://www.dimastr.com/redemption/) to get the From
> address or use Outlook to get the Reply To address, as
> Hans suggested. Sample code at
> http://www.slipstick.com/dev/code/getsenderaddy.htm.
> >

MJ

unread,
Feb 20, 2003, 9:05:55 AM2/20/03
to
I still need to play around w/ the reply to address some
more. The biggest problems I'm coming across are that I'm
trying to do this in C# and almost every example I see is
for VB.

I guess I'll have to look into Extended MAPI a bit as well
as the reply address.

I'm also having an issue registering the NewMail event.
I've even tried rebuilding the Interop.Outlook.dll as
suggested by a MS KB article. Any insight on that?

Thanks,
Mark

>.
>

Sue Mosher [MVP]

unread,
Feb 20, 2003, 5:24:07 PM2/20/03
to
C# officially has no support for CDO 1.21. Microsoft put out a KB article recently on that. I just read it yesterday.

I'd suggest you start a separate thread with details on your NewMail issue in the microsoft.public.outlook.program_addins newsgroup or a C# group. Outlook with .Net is full of pitfalls at the present time. Unless you have a burning need to use C#, a VB or Delphi or C++ approach might be better.

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

"MJ" <jaco...@yahoo.com> wrote in message news:071e01c2d8e9$2fbbeda0$a201...@phx.gbl...


> I still need to play around w/ the reply to address some
> more. The biggest problems I'm coming across are that I'm
> trying to do this in C# and almost every example I see is
> for VB.
>
> I guess I'll have to look into Extended MAPI a bit as well
> as the reply address.
>
> I'm also having an issue registering the NewMail event.
> I've even tried rebuilding the Interop.Outlook.dll as
> suggested by a MS KB article. Any insight on that?
>
> Thanks,
> Mark
>
> >-----Original Message-----
> >Same thing: To access the message headers, you must use
> CDO or Redemption or, in C++ or Delphi, Extended MAPI.
> >
> >You did see, didn't you, that you can easily get the
> reply address with Outlook objects only? That's more
> relevant than the actual From address in many cases.
> >
> >

Zucco

unread,
Feb 21, 2003, 12:57:20 PM2/21/03
to
Why CDO access is so slow ?

I have a code to get header if you want in CDO

Rajesh KAnungo

unread,
Feb 21, 2003, 9:06:03 PM2/21/03
to
Hi,
I tried all the suggestions posted to get the sender's
email address except for the CDO based program and they
all fail.

I acquire the mail item and I can not get the sender's
email address.

In the case of redemption code, SafeMailItem, the sender
field returns nothing.

The creation of a reply to a mailitem being sent also did
not work.
Any idea ?

Thank you.

>.
>

Sue Mosher [MVP]

unread,
Feb 21, 2003, 9:14:42 PM2/21/03
to
I'd suggest that you show the code you're using and explain the programming environment you're working in. Since those methods are known to work, you must have done something different.

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm


"Rajesh KAnungo" <kanu...@yahoo.com> wrote in message news:07d701c2da16$f3c45060$2f01...@phx.gbl...

Rajesh Kanungo

unread,
Feb 21, 2003, 11:12:33 PM2/21/03
to
Good idea. My apologies. I have enclosed the simplest
form. The code is run as an addin.
Description:
m_MailItemSend calls GetSenderAddress.
GetSenderAddress calls outlook redemption. Very close to
the posting on the slipstick.
I have marked the places where the results are wrong.
Also m_MailItem looks well formed.


Class foo ...
Private WithEvents m_MailItem As Outlook.MailItem

Private Sub m_MailItem_Send(Cancel As Boolean)
On Error Resume Next
Dim senderAddr as string
senderAddr = GetSenderAddress()
msgbox "I got an address !!! " & senderAddr
End Sub

Function GetSenderAddress() As String

Dim strType As String

Dim objSenderAE As Redemption.AddressEntry

Dim objSMail As Redemption.SafeMailItem

Const PR_SENDER_ADDRTYPE = &HC1E001E

Const PR_EMAIL = &H39FE001E

Set objSMail = CreateObject("Redemption.SafeMailItem")

objSMail.item = m_MailItem
' XXX strType : This comes back empty
strType = objSMail.Fields(PR_SENDER_ADDRTYPE)
' XXX objSenderAE comes back nothing
Set objSenderAE = objSMail.sender

If Not objSenderAE Is Nothing Then

If strType = "SMTP" Then

GetSenderAddress = objSenderAE.Address

ElseIf strType = "EX" Then

GetSenderAddress = objSenderAE.Fields(PR_EMAIL)

End If

End If

Set objSenderAE = Nothing

Set objSMail = Nothing
'Dim utils As Redemption.MAPIUtils
'Dim SenderEMail As String
'Set utils = CreateObject("Redemption.MAPIUtils")
'Const PrSenderEmailAddress = &HC1F001E
' XXX Even the following returns empty.
'SenderEMail = utils.HrGetOneProp(m_MailItem.MAPIOBJECT,
' PrSenderEmailAddress)
'MsgBox SenderEMail

End Function

>.
>

Sue Mosher [MVP]

unread,
Feb 21, 2003, 11:22:17 PM2/21/03
to
At the point where the Send event fires, Outlook has not yet set a sender address on the message. You would see sender addresses, however, if you monitored the Sent Items folder with an ItemAdd event handler. Perhaps this might be a good time to explain what you're really trying to accomplish here.

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm


"Rajesh Kanungo" <kanu...@yahoo.com> wrote in message news:030c01c2da28$9fabd220$a501...@phx.gbl...


> Good idea. My apologies. I have enclosed the simplest
> form. The code is run as an addin.
> Description:
> m_MailItemSend calls GetSenderAddress.
> GetSenderAddress calls outlook redemption. Very close to
> the posting on the slipstick.
> >

Rajesh Kanungo

unread,
Feb 22, 2003, 3:29:41 AM2/22/03
to
I went back and looked at what I wanted (again) given what
I have.

I Have: a received email to which I may reply.
I need: received email's sender and the recipient email
addresses.

I was trying to get the information from the newly created
reply but that is not necessary on second thoughts.

I will try to see if MailItem.ReceivedByName can be used
to get the email addresses.

-- Rajesh

>.
>

Sue Mosher [MVP]

unread,
Feb 22, 2003, 8:11:05 AM2/22/03
to
> I Have: a received email to which I may reply.
> I need: received email's sender

Use one of the methods given earlier. They will work quite differently on an already received message than on a new message that you are trying to send.

> and the recipient email addresses.

Enumerate the the MailItem.Recipients collection.

> I will try to see if MailItem.ReceivedByName can be used
> to get the email addresses.

If ReceivedByName returns anything on a message that *you* received, it will be *your* name.

Rajesh Kanungo

unread,
Feb 22, 2003, 6:23:55 PM2/22/03
to
Everything works like a charm :)
I did not state clearly the second part:
I need to know which account I
received the email on when I have more than one
account. The recipients collection gives me all the
recipients. MSO gives me the Friendly name, not the email
ID.

-- Rajesh

>.
>

Sue Mosher [MVP]

unread,
Feb 22, 2003, 6:53:33 PM2/22/03
to
If you wanted the receiving account, then why did you ask about the sender address? To find out who the message was sent to -- in other words, which of your addresses you received it with -- you can loop through the Recipients collection and check the Address property of each Recipient. Of course, you won't find yourself there if you received the message as a blind CCs.

An alternative technique is to use CDO or Redemption to obtain the SMTP headers for the message. See http://www.slipstick.com/dev/olforms/headers.htm for an Outlook form that demonstrates the technique.

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

"Rajesh Kanungo" <kanu...@yahoo.com> wrote in message news:03dd01c2dac9$77b382d0$a001...@phx.gbl...

0 new messages