【发布时间】:2022-05-24 08:59:53
【问题描述】:
我可以帮助修改 Outlook VBA 宏。每当我从我的多个电子邮件帐户中的任何一个回复电子邮件时,脚本都会将发件人地址更改为指定的地址(即 user@domain.com 代表 group@domain.com)。我喜欢这种行为,但需要帮助进行更改,以便此脚本仅在我从电子邮件地址@domain.com 发送时运行。本质上,我希望宏有一个 if 语句,指定是否从 @domain.com 电子邮件帐户发送然后运行宏,否则如果从另一个电子邮件帐户(即 user@gmail.com)发送不运行宏。
'================================================================================
'Description: Outlook macro to automatically set a different
' From address.
'
'Comment: You can set the email address at the bottom of the code.
' Uncomment the myOlExp_InlineResponse sub to also make it
' work with the Reading Pane reply feature of Outlook 2013/2016/2019/365.
'
' author : Robert Sparnaaij
' version: 1.1
' website: https://www.howto-outlook.com/howto/setfromaddress.htm
'================================================================================
Dim WithEvents objInspectors As Outlook.Inspectors
Dim WithEvents objMailItem As Outlook.MailItem
Dim WithEvents myOlExp As Outlook.Explorer
Private Sub Application_Startup()
Initialize_handler
End Sub
Public Sub Initialize_handler()
Set objInspectors = Application.Inspectors
Set myOlExp = Application.ActiveExplorer
End Sub
Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
If Inspector.CurrentItem.Class = olMail Then
Set objMailItem = Inspector.CurrentItem
If objMailItem.Sent = False Then
Call SetFromAddress(objMailItem)
End If
End If
End Sub
'Uncomment the next 3 lines to enable Outlook 2013/2016/2019/365 Reading Pane Reply
'Private Sub myOlExp_InlineResponse(ByVal objItem As Object)
' Call SetFromAddress(objItem)
'End Sub
Public Sub SetFromAddress(oMail As Outlook.MailItem)
' Set your preferred default From address below.
' Exchange permissions determine if it is actually stamped
' as "Sent On Behalf Of" or "Sent As".
' The address is not properly updated for the InlineResponse
' feature in Outlook 2013/2016/365. This is only a visual bug.
oMail.SentOnBehalfOfName = "delegate@domain.com"
End Sub
【问题讨论】:
-
代码不是VBScript。
-
如果有使用帐户的回复,您会确认电子邮件地址也是帐户。在这个answer post中运行
ShowAllAccounts代码