vba - 通过 VBA 在撰写模式下在 Outlook 上返回发件人/发件人地址
问题描述
我在 Outlook 上只有一个交换帐户,可以访问两个由管理员创建的共享/组邮箱或邮件地址。我只是该共享邮件组的成员,我可以通过它们发送和接收邮件。所以有时我会因为选择错误的发件人地址而犯错误。在发送电子邮件之前,我需要检查发件人/发件人地址和收件人。但是,我无法通过 VBA 将发件人/发件人地址作为字符串返回。我通过“来自”下拉菜单选择它们。
这是我的代码:
Dim Recipients As Outlook.Recipients
Dim recip As Outlook.Recipient
Dim i
Dim prompt As String
Dim Send_Address As String
Dim checker As Integer
Send_Address = Item.SendUsingAccount.SmtpAddress
checker = 0
Set Recipients = Item.Recipients
For i = Recipients.Count To 1 Step -1
Set recip = Recipients.Item(i)
If InStr(LCase(recip.Address), "abc.com") Then
checker = 1
End If
If InStr(LCase(recip.Address), "xyz.com") Then
checker = 2
End If
Next i
If (Send_Address = "abc.om") And (checker = 1) Then
MsgBox ("Please check CC list. It includes different clients.")
Cancel = True
ElseIf (Send_Address = "xyz.com") And (checker = 2) Then
MsgBox ("Please check CC list. It includes different clients.")
Cancel = True
Else
MsgBox ("OK" & checker & Send_Address)
Cancel = True
End If
End Sub
解决方案
From 值在.SentOnBehalfOfName
. 它不会在 GUI 更改时更新。
用代码更新值。GUI 将保持不变。
Option Explicit
Sub updateFromValue()
Dim Item As mailItem
Dim mailbox1 As String
Dim mailbox2 As String
Dim mailbox3 As String
Dim resp As String
' first create a draft for testing
Set Item = ActiveInspector.currentItem
Item.Display
Debug.Print ".SentOnBehalfOfName: " & Item.SentOnBehalfOfName
mailbox1 = "abc.com"
mailbox2 = "xyz.com"
mailbox3 = "default.com"
resp = InputBox("1: " & mailbox1 & vbCr & "2: " & mailbox2 & vbCr & "3: " & mailbox3)
If Len(resp) > 0 Then
Select Case resp
Case 1
Item.SentOnBehalfOfName = mailbox1
Debug.Print "Item.SentOnBehalfOfName: " & Item.SentOnBehalfOfName
Case 2
Item.SentOnBehalfOfName = mailbox2
Debug.Print "Item.SentOnBehalfOfName: " & Item.SentOnBehalfOfName
Case 3
Item.SentOnBehalfOfName = mailbox3
Debug.Print "Item.SentOnBehalfOfName: " & Item.SentOnBehalfOfName
Case Else
Debug.Print "?"
End Select
End If
End Sub
现在您可以验证.SentOnBehalfOfName
Application_ItemSend 中的值。
推荐阅读
- javascript - React 应用无法导入使用 webpack 打包的 react 应用
- api - 虚拟主机面板架构
- javascript - document.cookie 过期无法在 Safari 中正常工作
- python - 在 Python 中运行时创建的 Linting 类
- reactjs - 在 redux-form 中,在 Field-Level Validation 中显示所有验证错误
- c# - 如何制作一个仅使用加法和仅使用 2 个变量进行除法的递归函数
- flutter - Flutter 用 provider 和 riverpod 制作表单
- typescript - Typescript: How to kleisli compose (monadic compose) Promise monad using fp-ts
- c# - 应该使用什么类型的参数来将方法作为输入?
- python - 回文测试器给出 11 的 False,但返回 121 的 True