gpt4 book ai didi

vba - 如何从Outlook的 'To'字段中提取电子邮件地址?

转载 作者:行者123 更新时间:2023-12-03 15:23:05 25 4
gpt4 key购买 nike

我一直在使用VBA,使用以下代码:

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

但是,这将输出作为电子邮件地址的名称,而不是带有 "something@this.domain" 的实际电子邮件地址。

是否存在mailobject的属性,该属性将允许从 'To' 文本框中写入电子邮件地址而不是名称。

谢谢

最佳答案

checkout 您的邮件项目的“收件人”收集对象,该对象应允许您获取地址:http://msdn.microsoft.com/en-us/library/office/ff868695.aspx

更新8/10/2017

回顾这个答案,我意识到我只是通过链接某处而不提供更多信息而做得不好。

这是上面那个MSDN链接的代码片段,显示了如何使用收件人对象来获取电子邮件地址(该片段在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

关于vba - 如何从Outlook的 'To'字段中提取电子邮件地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12641704/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com