我正在尝试检查我的电子邮件收件人是否在 Outlook 2016 的全局地址列表中。
如果所有收件人都是内部的(我们的 GAL 仅包括内部地址),则消息将被释放。
如果至少有一个收件人是外部的(来自 GAL 之外),那么我应该收到一条警告消息,询问我是否仍要发送此电子邮件。
我尝试了这个主题,但我需要一个解决方案,而无需将地址复制到外部 Excel 电子表格。
我也使用过这个解决方案,但我们公司很大,在全球有多个分支机构。引用的解决方案检查我的域是否与收件人域相同。当我试图向来自我公司但在我所在地区之外的人发送电子邮件时会出现问题 - 我来自 EMEA,例如我正在向 PAM 发送电子邮件。不幸的是,这个解决方案目前还不够。因为 PAM 使用不同的域 - 出现警告消息。
对我来说最简单的方法是检查 GAL 中的收件人,但我不确定这是否可能。
下面第二个解决方案的代码:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim recips As Outlook.Recipients
Dim recip As Outlook.Recipient
Dim pa As Outlook.propertyAccessor
Dim prompt As String
Dim Address As String
Dim lLen
Dim strMyDomain
Dim internal As Long
Dim external As Long
Const PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
' non-exchange
' userAddress = Session.CurrentUser.Address
' use for exchange accounts
userAddress = Session.CurrentUser.AddressEntry.GetExchangeUser.PrimarySmtpAddress
lLen = Len(userAddress) - InStrRev(userAddress, "@")
strMyDomain = Right(userAddress, lLen)
Set recips = Item.Recipients
For Each recip In recips
Set pa = recip.propertyAccessor
Address = LCase(pa.GetProperty(PR_SMTP_ADDRESS))
lLen = Len(Address) - InStrRev(Address, "@")
str1 = Right(Address, lLen)
If str1 = strMyDomain Then internal = 1
If str1 <> strMyDomain Then external = 1
Next
If internal + external = 2 Then
prompt = "This email is being sent to Internal and External addresses. Do you still wish to send?"
If MsgBox(prompt, vbYesNo + vbExclamation + vbMsgBoxSetForeground, "Check Address") = vbNo Then
Cancel = True
End If
End If
End Sub