我编写了一个脚本,根据excel电子表格的内容将传入的电子邮件转发给合适的人。
问题在于,通过将收件人的名称放入邮件的.To
字段(即John Smith - 而不是john.smith@example.com),然后查找实际地址当我调用.Send
方法时,Outlook似乎决定有时通过“LinkedIn Social Connector”查找联系人电子邮件地址。
如何强制它在“全球地址列表”中查找此人的电子邮件地址?
答案 0 :(得分:1)
您可以从GAL获取地址,而不是让Outlook确定它。
来自此处的示例http://msdn.microsoft.com/en-us/library/office/ff869721(v=office.15).aspx
未经测试的代码
Option Explicit
Sub DemoAE_ToName
Dim colAL As Outlook.AddressLists
Dim oAL As Outlook.AddressList
Dim colAE As Outlook.AddressEntries
Dim oAE As Outlook.AddressEntry
Dim oExUser As Outlook.ExchangeUser
Set colAL = Application.Session.AddressLists
For Each oAL In colAL
'Address list is an Exchange Global Address List
If oAL.AddressListType = olExchangeGlobalAddressList Then
Set colAE = oAL.AddressEntries
For Each oAE In colAE
' no distribution lists
If oAE.AddressEntryUserType = _
olExchangeUserAddressEntry _
Or oAE.AddressEntryUserType = _
olExchangeRemoteUserAddressEntry Then
If oAE.Name = "John Smith" then
Set oExUser = oAE.GetExchangeUser
Debug.Print (oExUser.PrimarySmtpAddress)
end if
End If
Next
End If
Next
End Sub
您可以设置一个函数来传递ToName并返回oExUser.PrimarySmtpAddress
而不是
For Each oAL In colAL
If oAL.AddressListType = olExchangeGlobalAddressList Then
您应该可以使用
删除一些代码Set oAL = Application.Session.AddressLists("Global Address List")
编辑:回复:评论 - 艰难的人群。
编辑2:出现限制不可用
经过测试的代码,在知道名称时检索地址。
Sub AddressEntry_DirectAccess()
Dim oNS As Namespace
Dim oExUser As exchangeUser
Set oNS = Application.GetNamespace("MAPI")
Set oExUser = oNS.AddressLists("Global Address List").AddressEntries("Last, First").GetExchangeUser()
If Not oExUser Is Nothing Then
Debug.Print oExUser.name & ": " & oExUser.PrimarySmtpAddress
End If
End Sub
答案 1 :(得分:0)
首先,如果按Ctrl + Shift + B,工具|,则可以在Outlook中指定正确的名称解析顺序选项。
如果您使用的是C ++或Delphi,则可以使用扩展MAPI:检索GAL的IABContainer接口并应用PR_ANR限制。
如果您使用Redemption是一个选项,则可以使用RDOSession.AddressBook.GAL检索GAL容器,然后使用RDOAddressList.ResolveName来解析该特定容器。