跳至主要内容

如何在通过Outlook发送之前检查收件人地址?

Author: Sun Last Modified: 2025-05-07

有时,您可能会在通过Outlook发送电子邮件时遗漏将一些重要收件人添加到“收件人”、“抄送”或“密件抄送”字段中。在这里,我可以介绍一种方法,在通过Outlook发送之前检查特定的电子邮件地址是否已添加。

使用VBA代码在发送前检查地址


使用VBA代码在发送前检查地址

这里我有两个代码可以帮助您解决这个问题,您可以根据需要选择其中之一。

1. 按 Alt + F11 键以启用 Microsoft Visual Basic for Applications 窗口。

2. 在“项目1”窗格中双击 ThisOutlookSession 以打开代码编辑器,复制并将以下代码粘贴到编辑器中。

VBA:在发送前检查“收件人”字段中的地址

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
'UpdatebyExtendoffice20180523
Dim xAddressArr() As Variant
Dim xAddress As String
Dim xRecipient As Recipient
Dim xPrompt As String
Dim xYesNo As Integer
Dim xDictionary As Scripting.Dictionary
On Error Resume Next
Set xDictionary = New Scripting.Dictionary
xAddressArr = Array("example1@126.com", "example2@126.com", "example3@126.com")
For i = LBound(xAddressArr) To UBound(xAddressArr)
    xDictionary.Add xAddressArr(i), True
Next i
For Each xRecipient In Item.Recipients
    If xRecipient.Type = olTo Then
        If xDictionary.Exists(xRecipient.Address) Then xDictionary.Remove xRecipient.Address
    End If
Next
If xDictionary.Count = 0 Then GoTo L1
For i = 0 To xDictionary.Count - 1
    If xAddress = "" Then
        xAddress = xDictionary.Keys(i)
    Else
        xAddress = xAddress + "; " & xDictionary.Keys(i)
    End If
Next i
xPrompt = "You are not sending this to: " & xAddress & ". Are you sure you want to send the Mail?"
xYesNo = MsgBox(xPrompt, vbQuestion + vbYesNo, "Kutools for Outlook")
If xYesNo = vbNo Then Cancel = True
L1:
  Set xRecipient = Nothing
  Set xDictionary = Nothing
End Sub

doc check recipient address before sending 1

在代码中,您可以将 ("example1@126.com", "example2@126.com", "example3@126.com") 更改为实际需要的收件人。

3. 然后同样在 Microsoft Visual Basic for Applications 窗口中,点击 工具 > 引用。在“引用-项目1”对话框中勾选 Microsoft Scripting Runtime 复选框。

doc check recipient address before sending 2 doc arrow right doc check recipient address before sending 3

4. 单击 确定 并保存代码。

现在,如果指定的收件人未出现在发送邮件时的“收件人”字段中,将会弹出一个对话框提醒您是否要发送该邮件。
doc check recipient address before sending 4

使用上述代码,它仅检查“收件人”字段中的电子邮件地址。如果您想检查“收件人”“抄送”“密件抄送”字段,可以使用以下代码。

VBA:在发送前检查“收件人/抄送/密件抄送”字段中的地址

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
'UpdatebyExtendoffice20180523
Dim xRecipients As Outlook.Recipients
Dim xRecipient As Outlook.Recipient
Dim xPos As Integer
Dim xYesNo As Integer
Dim xPrompt As String
Dim xAddress As String
On Error Resume Next
If Item.Class <> olMail Then Exit Sub
Set xRecipients = Item.Recipients
xAddress = "example1@gmail.com"
For Each xRecipient In xRecipients
    xPos = InStr(LCase(xRecipient.Address), xAddress)
    If xPos = 0 Then
        xPrompt = "You sending this to " & xAddress & ". Are you sure you want to send it?"
        xYesNo = MsgBox(xPrompt, vbYesNo + vbQuestion + 4096, "Kutools for Outlook")
        If xYesNo = vbNo Then Cancel = True
    End If
Next xRecipient
End Sub

使用此代码,您无需勾选 Microsoft Scripting Runtime 复选框,只需直接保存代码即可生效。

Outlook中的AI邮件助手:更智能的回复,更清晰的沟通(一键搞定!) 免费

使用Kutools for Outlook的AI邮件助手简化您的日常Outlook任务。这一强大工具会从您过去的邮件中学习,提供智能化且精准的回复建议,优化您的邮件内容,并帮助您轻松起草和润色邮件。
doc ai email handle

该功能支持:

  • 智能回复:根据您以往的对话生成量身定制、精准且即用的回复。
  • 增强内容:自动优化您的邮件文本,使其更加清晰且有影响力。
  • 轻松撰写:只需提供关键字,AI即可完成其余工作,并支持多种写作风格。
  • 智能扩展:通过上下文感知的建议扩展您的思路。
  • 总结概括:快速获取长邮件的简洁概述。
  • 全球覆盖:轻松将您的邮件翻译成任何语言。

该功能支持:

  • 智能邮件回复
  • 优化后的内容
  • 基于关键字的草稿
  • 智能内容扩展
  • 邮件总结
  • 多语言翻译

最重要的是,此功能永久完全免费不要再犹豫了——立即下载AI邮件助手并体验吧