Skip to main content

如何在通過 Outlook 發送之前檢查收件人地址?

Author: Sun Last Modified: 2025-05-12

有時候,您可能會在通過 Outlook 發送電子郵件時,忘記將一些重要的收件人添加到「收件人」、「抄送」或「密件抄送」欄位中。在這裡,我將介紹一種方法,在通過 Outlook 發送之前檢查特定的郵件地址是否已經被添加。

使用 VBA 代碼在發送前檢查地址


使用 VBA 代碼在發送前檢查地址

這裡我有兩個代碼可以幫助您完成這項工作,您可以根據需要選擇其中之一。

1. 按 Alt + F11 鍵以啟用 Microsoft Visual Basic for Applications 視窗。

2. 在 Project1 窗格中雙擊 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 視窗中,點擊 工具 > 參考。在 References-Project1 對話框中勾選 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郵件助理並享受吧