【发布时间】:2021-12-30 18:16:10
【问题描述】:
我在 Outlook 中使用多个帐户。如果从我不应该发送的地址发送,我想给出一个警告框。
我有两个永远不应该发送的地址(它们是只接收帐户)。
这个例子几乎就是我要找的。 Example - Checking the "To" address.
我相信字符串比较 (StrComp) 和 Item.SenderEmailAddress 是我需要的。
这是我对单个电子邮件地址 (bad.email@gmail.com) 发出警告的尝试。
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
On Error Resume Next
' use lower case for the address
' LCase converts all addresses in the To field to lower case
If StrComp((Item.SenderEmailAddress), "bad.email@gmail.com") Then
Exit Sub
End If
Prompt$ = "You sending this from " & Item.SenderEmailAddress & ". Are you sure you want to send it?"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
Cancel = True
End If
End Sub
理想情况下,我会使用相同的代码检查两个或多个地址。示例中的内容应该可以工作。
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
On Error Resume Next
Select Case LCase(Item.To)
Case "alias@domain.com", "alias2@domain3.com", "alias3@domain3.com"
Item.Send
Case Else
Prompt$ = "You are not sending this to " & Item.To & ". Are you sure you want to send the Mail?"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
Cancel = True
End If
End Select
End Sub
另外,我应该将代码放在哪里以确保它不断运行并准备就绪?
【问题讨论】:
-
" SenderEmailAddress "返回一个字符串,表示 Outlook 项目的发件人的电子邮件地址。只读。"未发送的邮件中不存在。
-
你查看的是发件人地址还是收件人地址?
-
检查发件人(发件人)地址