Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract Email address from To line of Outlook form

Status
Not open for further replies.

tzq99

Technical User
Apr 15, 2011
3
DE
Hello

I'm creating a message template in Microsoft Outlook, with various custom fields.

One thing I need to do is record the raw email address (like joe@shmoe.com) of the sender and the recipient in custom fields. The code is being run while the user is composing the email, but after they put a name in the To line.

For the sender's email address, I have no problem, I am using this code:

txtSenderEmail.value = Application.GetNameSpace("MAPI").CurrentUser.Address

I have no problem capturing the recipient name resolved in the To line, but I want their email address only. I have

txtRecipientEmail = Item.To

In the To line it shows 'Joe Shmoe <joe@shmoe.com>' but that returns their name only to my txtRecipientEmail like 'Joe Shmoe'.

How can I extract only the SMTP email from this, and can I get to work for both Exchange Server recipients and SMTP recipients likewise?

Thanks in advance.
 
What about this ?
txtRecipientEmail = Mid(Left(Item.To, InStr(Item.To, ">") - 1), 1 + InStr(Item.To, "<"))

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
unfortunatly this doesnt work because what is being returned is:

Joe Shmoe

not

Joe Shmoe <joe@shmoe.com>


(The problem is in VBScript, in case that wasnt clear.)
 
And this ?
txtRecipientEmail = Item.Recipients(0).Address

You may have to replace (0) with (1).

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
txtRecipientEmail = Item.Recipients(1).Address worked perfectly for my IMAP-connected Outlook!!! Thanks

Now I just have to try it with the exchange server addresses.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top