Get email address from MailItem.To?

Status
Not open for further replies.
M

Mark B

VSTO OL2007 C#

When I am sending an email, how do I extract the email address component

from the TO field?

MailItem.Recipients field doesn't have any objects in the list before

Outlook sends an item. MailItem.To just has address book names and not email

addresses.
 
Trap the item.Send() event and in that event save the item then read the

recipient properties you want.

"Mark B" <none123@none.com> wrote in message

news:O4wauetKKHA.4392@TK2MSFTNGP04.phx.gbl...
> VSTO OL2007 C#

> When I am sending an email, how do I extract the email address component
> from the TO field?

> MailItem.Recipients field doesn't have any objects in the list before
> Outlook sends an item. MailItem.To just has address book names and not
> email addresses.
 
Please excuse any newbie ignorance on this but I put a breakpoint after the

following code to see what mail.Recipients would expose for me in the

immediate window:

Outlook.MailItem mail1 = Item as Outlook.MailItem;

mail1.Save();

I could get mail1.Recipients.Count to return me 1. I thought

mail1.Recipients(1).emailaddress or similar would return me the raw email

address of the first recipient but I couldn't see that type of thing.

What code would I need to return me the email address?
<kenslovak@mvps.org> wrote in message

news:egw4iVwKKHA.4168@TK2MSFTNGP05.phx.gbl...
> Trap the item.Send() event and in that event save the item then read the
> recipient properties you want.

> >

>

> "Mark B" <none123@none.com> wrote in message
> news:O4wauetKKHA.4392@TK2MSFTNGP04.phx.gbl...
> > VSTO OL2007 C#
>

>> When I am sending an email, how do I extract the email address component
> > from the TO field?
>

>> MailItem.Recipients field doesn't have any objects in the list before
> > Outlook sends an item. MailItem.To just has address book names and not
> > email addresses.

>
 
mail1.Recipients.Item(1).Address

should work.

Dmitry Streblechenko (MVP)

-

"Mark B" <none123@none.com> wrote in message

news:%23uMaVKELKHA.1248@TK2MSFTNGP04.phx.gbl...
> Please excuse any newbie ignorance on this but I put a breakpoint after
> the following code to see what mail.Recipients would expose for me in the
> immediate window:

> Outlook.MailItem mail1 = Item as Outlook.MailItem;
> mail1.Save();

> I could get mail1.Recipients.Count to return me 1. I thought
> mail1.Recipients(1).emailaddress or similar would return me the raw email
> address of the first recipient but I couldn't see that type of thing.

> What code would I need to return me the email address?

> " - " <kenslovak@mvps.org> wrote in message
> news:egw4iVwKKHA.4168@TK2MSFTNGP05.phx.gbl...
> > Trap the item.Send() event and in that event save the item then read the
> > recipient properties you want.
>

>> > >

> >

>

>
>
>
>
>
>> "Mark B" <none123@none.com> wrote in message
> > news:O4wauetKKHA.4392@TK2MSFTNGP04.phx.gbl...
> >> VSTO OL2007 C#
> >
>>> When I am sending an email, how do I extract the email address component
> >> from the TO field?
> >
>>> MailItem.Recipients field doesn't have any objects in the list before
> >> Outlook sends an item. MailItem.To just has address book names and not
> >> email addresses.

> >

>
 
"Error 7 'Microsoft.Office.Interop.Outlook.Recipients' does not contain a

definition for 'Item' and no extension method 'Item' accepting a first

argument of type 'Microsoft.Office.Interop.Outlook.Recipients' could be

found (are you missing a using directive or an assembly reference?)"

"Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message

news:%235giqhFLKHA.3632@TK2MSFTNGP05.phx.gbl...
> mail1.Recipients.Item(1).Address
> should work.
> > Dmitry Streblechenko (MVP)
>

>

>

> -
> "Mark B" <none123@none.com> wrote in message
> news:%23uMaVKELKHA.1248@TK2MSFTNGP04.phx.gbl...
> > Please excuse any newbie ignorance on this but I put a breakpoint after
> > the following code to see what mail.Recipients would expose for me in the
> > immediate window:
>

>> Outlook.MailItem mail1 = Item as Outlook.MailItem;
> > mail1.Save();
>

>> I could get mail1.Recipients.Count to return me 1. I thought
> > mail1.Recipients(1).emailaddress or similar would return me the raw email
> > address of the first recipient but I couldn't see that type of thing.
>

>> What code would I need to return me the email address?
>

>
>
>> " - " <kenslovak@mvps.org> wrote in message
> > news:egw4iVwKKHA.4168@TK2MSFTNGP05.phx.gbl...
> >> Trap the item.Send() event and in that event save the item then read the
> >> recipient properties you want.
> >
>>> > >>

> >>

> >
>>
>>
>>
>>
>>
>>> "Mark B" <none123@none.com> wrote in message
> >> news:O4wauetKKHA.4392@TK2MSFTNGP04.phx.gbl...
> >>> VSTO OL2007 C#
> >>
>>>> When I am sending an email, how do I extract the email address
> >>> component from the TO field?
> >>
>>>> MailItem.Recipients field doesn't have any objects in the list before
> >>> Outlook sends an item. MailItem.To just has address book names and not
> >>> email addresses.
> >>

> >


>
 
In C# it would be mail1.Recipients[1].

"Mark B" <none123@none.com> wrote in message

news:%230Fxi1FLKHA.2404@TK2MSFTNGP04.phx.gbl...

> "Error 7 'Microsoft.Office.Interop.Outlook.Recipients' does not contain a
> definition for 'Item' and no extension method 'Item' accepting a first
> argument of type 'Microsoft.Office.Interop.Outlook.Recipients' could be
> found (are you missing a using directive or an assembly reference?)"
 
Thanks Ken, that works.
<kenslovak@mvps.org> wrote in message

news:%23lFvejJLKHA.5992@TK2MSFTNGP03.phx.gbl...
> In C# it would be mail1.Recipients[1].

> >

>

> "Mark B" <none123@none.com> wrote in message
> news:%230Fxi1FLKHA.2404@TK2MSFTNGP04.phx.gbl...
>

>> "Error 7 'Microsoft.Office.Interop.Outlook.Recipients' does not contain a
> > definition for 'Item' and no extension method 'Item' accepting a first
> > argument of type 'Microsoft.Office.Interop.Outlook.Recipients' could be
> > found (are you missing a using directive or an assembly reference?)"

>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
P Email address auto-completes work fine on laptop, but no longer on desktop Using Outlook 2
H Copying email address(es) in body of email and pasting in To field Outlook VBA and Custom Forms 1
P VBA to add email address to Outlook 365 rule Outlook VBA and Custom Forms 0
Rupert Dragwater How to permanently remove an email address Using Outlook 9
L Specific Incoming Email Address Immediately Deleted Using Outlook 2
H Preventing the 'email address fetch from Exchange' crashing email reading code Exchange Server Administration 0
D multiple email accounts - why do I have to choose the "from" account address?? Using Outlook 2
O What would be the recommended way to change an email address (family member)? Using Outlook 0
L Checking Sender Email Address for trusted domain from list on intranet Outlook VBA and Custom Forms 4
J How do you disable address search box when typing @ in body of email? Using Outlook 0
Victor.Ayala Automated way to check the option "Show this folder as an email Address Book" Outlook VBA and Custom Forms 2
D Wrong email address in Outlook 2003 "From" tab in new outgoing emails Using Outlook 4
e_a_g_l_e_p_i Outlook 2010 How to set default email address for website links Using Outlook 3
O Same email address, same person, names in so many ways Using Outlook 4
D auto forward base on email address in body email Outlook VBA and Custom Forms 0
N contact list seen in Contact folder but knot in Address book or when 'TO' button is clicked in new email Using Outlook 0
C WARNING - DO NOT USE AN OUTLOOK.COM ADDRESS FOR GOOGLE ACCOUNT RECOVERY EMAIL Using Outlook 10
L Email with correct To address but displaying name of a related person Using Outlook 0
B Extracting email addresses from a folder - how to also get the name of the person the address is for? Using Outlook 5
W Replyin to the reply-to email address Outlook VBA and Custom Forms 0
J Sent Items Folder NOT Showing Correct From Email Address Using Outlook 0
J Outlook Reply > From > Other Email Address... > Address Not Showing in Sent Items... From Email Outlook VBA and Custom Forms 0
C Outlook Autocomplete suggestions showing wrong person's name against an email address Using Outlook 0
Healy Consultants Macro to remove inside organization distribution list email address when reply to all recepients Outlook VBA and Custom Forms 0
L Email not going to address displayed Using Outlook 4
B When sending an email, I am showing 2 of my address's Using Outlook 1
oliv- determine to which address an email has been sent Outlook VBA and Custom Forms 3
S Outlook 2007 printing wrong email address at top of page Using Outlook 8
B Looking to get the Recipient email address (or even the "friendly name") from an email I am replying to using VBA Outlook VBA and Custom Forms 4
Rupert Dragwater Deleted email address keeps showing up in reply Using Outlook 12
O How to display senders email address (column) Using Outlook 1
B When working on emails in a certain folder, when I hit reply or reply all, I would like it re always reply all and add an email address to send to Outlook VBA and Custom Forms 3
I How to display sender's name instead of email address in outlook 2013 message Using Outlook 5
L Hubby and Wife names in email address Using Outlook 1
J Signatures that contain recipient's email address Outlook VBA and Custom Forms 7
L Using alpha numeric in email address Using Outlook 5
T Have Outlook 2016 suggest email address auto complete entries directly from the user's contacts list Using Outlook 10
T Have Outlook 2016 suggest email address auto complete entries directly from the user's contacts list Using Outlook 0
C address book "when sending email" bug? Using Outlook 0
J Help Needed With Multi-Step Login Email Address Using Outlook.com accounts in Outlook 1
Brostin Forward a mail to the address listed in the email text Outlook VBA and Custom Forms 1
M Want to autorespond to an email address in the body of message Using Outlook 0
G How to filter by the format of an email address Using Outlook 6
K Extract email address from body and auto-reply outlook Using Outlook 1
D Column for To Email Address Using Outlook 0
C Why can junk mail be from one’s own email address? Using Outlook 7
B Can't expose sender email address when linking outlook to access Using Outlook 3
W Inserting Additional Email Address Outlook VBA and Custom Forms 4
G Create an Appointment at the Contact's Address From Email Outlook VBA and Custom Forms 0
Diane Poremsky Warn before sending messages to the wrong email address Using Outlook 1

Similar threads

Back
Top