【发布时间】:2013-07-19 09:43:30
【问题描述】:
如果您要向外部域发送和发送电子邮件,如何让Outlook 发出警告?
每天发送大量电子邮件,总是有可能将一封错误地发送给错误的人。当他们是您公司以外的客户或人员时,这尤其是一个问题。
在为我输入电子邮件后使用Alt + Enter 快速发送电子邮件通常是原因,因为我没有彻底检查收件人。
我发现了很多不太好的实现,所以我想我会在下面分享我的......
【问题讨论】:
如果您要向外部域发送和发送电子邮件,如何让Outlook 发出警告?
每天发送大量电子邮件,总是有可能将一封错误地发送给错误的人。当他们是您公司以外的客户或人员时,这尤其是一个问题。
在为我输入电子邮件后使用Alt + Enter 快速发送电子邮件通常是原因,因为我没有彻底检查收件人。
我发现了很多不太好的实现,所以我想我会在下面分享我的......
【问题讨论】:
感谢 ojhhawkins 提供上面的代码 - 非常有用。我做了一个简单的迭代,在 MsgBox 文本中包含一个外部电子邮件地址列表。
注意事项 - 我注意到当您在其他程序(例如 Excel、Adobe Reader 等)中使用“作为电子邮件附件发送”时不会出现警告。正如 niton 指出的那样:
Re:在其他程序中以电子邮件附件形式发送。在此处的注释中有说明 outlookcode.com/d/code/setsavefolder.htm “...不适用于使用 File | Send 命令在 Office 程序或 Windows 资源管理器或其他程序中的类似命令创建的消息。这些命令调用 Simple MAPI,它绕过 Outlook 功能。”
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 strMsg As String
Const PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
Set recips = Item.Recipients
For Each recip In recips
Set pa = recip.PropertyAccessor
If InStr(LCase(pa.GetProperty(PR_SMTP_ADDRESS)), "@example.com") = 0 Then
strMsg = strMsg & " " & pa.GetProperty(PR_SMTP_ADDRESS) & vbNewLine
End If
Next
If strMsg <> "" Then
prompt = "This email will be sent outside of example.com to:" & vbNewLine & strMsg & "Do you want to proceed?"
If MsgBox(prompt, vbYesNo + vbExclamation + vbMsgBoxSetForeground, "Check Address") = vbNo Then
Cancel = True
End If
End If
End Sub
要将此代码实际添加到您的 Outlook 应用程序中:
【讨论】:
如果您不想使用 VBA,我发现了两个 Outlook 加载项,它们的作用相同,
【讨论】:
将以下代码添加到 Outlook 中的 Application_ItemSend 事件并将域更改为您自己的域
将Macro Security 更改为(通知所有宏或启用所有宏)
如果您的TO、CC 或BCC 地址中有一个或多个不在您的域中(例如@mycompany.com.au 下方),这将在发送前向您发出警告
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
Const PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
Set recips = Item.Recipients
For Each recip In recips
Set pa = recip.PropertyAccessor
If InStr(LCase(pa.GetProperty(PR_SMTP_ADDRESS)), "@mycompany.com.au") = 0 Then
If MsgBox("Send mail to external domain?", vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
Cancel = True
Exit Sub
Else
Exit Sub
End If
End If
Next
End Sub
【讨论】: