How do you extract email addresses from the To field in Outlook?

I use VBA to some extent using this code:

Sub ExtractEmail() Dim OlApp As Outlook.Application Dim Mailobject As Object Dim Email As String Dim NS As NameSpace Dim Folder As MAPIFolder Set OlApp = CreateObject("Outlook.Application") ' Setup Namespace Set NS = ThisOutlookSession.Session ' Display select folder dialog Set Folder = NS.PickFolder ' Create Text File Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.CreateTextFile("c:\mydocuments\emailss.txt", True) ' loop to read email address from mail items. For Each Mailobject In Folder.Items Email = Mailobject.To a.WriteLine (Email) Next Set OlApp = Nothing Set Mailobject = Nothing a.Close End Sub 

However, this gives the output as the names of email addresses, rather than the actual email address using " something@this.domain " .

Is there a mail object attribute that allows email addresses, not names, to be written in the 'To' text box.

thanks

+6
source share
1 answer

Browse the recipient collection object for your mail item, which will allow you to get the address: http://msdn.microsoft.com/en-us/library/office/ff868695.aspx


Update 10/10/2017

Looking back at this answer, I realized that I did something bad, only by contacting somewhere and not providing a bit more information.

Here is a snippet of code from the above MSDN link showing how the Recipients object can be used to get an email address (the snippet is in VBA):

 Sub GetSMTPAddressForRecipients(mail As Outlook.MailItem) Dim recips As Outlook.Recipients Dim recip As Outlook.Recipient Dim pa As Outlook.PropertyAccessor Const PR_SMTP_ADDRESS As String = _ "http://schemas.microsoft.com/mapi/proptag/0x39FE001E" Set recips = mail.Recipients For Each recip In recips Set pa = recip.PropertyAccessor Debug.Print recip.name &; " SMTP=" _ &; pa.GetProperty(PR_SMTP_ADDRESS) Next End Sub 
+10
source

Source: https://habr.com/ru/post/926516/


All Articles