Vba 自动地;代“发送”;从特定电子邮件帐户发送时
我可以使用帮助修改Outlook VBA宏。每当我从多个电子邮件帐户中的任何一个帐户回复电子邮件时,脚本都会将发件人地址更改为指定的地址(即。user@domain.com代表group@domain.com). 我喜欢这种行为,但需要帮助进行更改,以便此脚本仅在我通过电子邮件地址@domain.com发送时运行。基本上,我希望宏有一个if语句,指定是否从@domain.com电子邮件帐户发送,如果从另一个电子邮件帐户发送,则运行宏。user@gmail.com不要运行宏Vba 自动地;代“发送”;从特定电子邮件帐户发送时,vba,outlook,Vba,Outlook,我可以使用帮助修改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
如果要处理传出的电子邮件,则需要订阅应用程序类的事件,该事件在用户通过检查器(在检查器关闭之前,但在用户单击“发送”按钮之后)或Outlook项目的发送方法(如MailItem)发送Microsoft Outlook项目时触发,在程序中使用
Public WithEvents myOlApp As Outlook.Application
Public Sub Initialize_handler()
Set myOlApp = Outlook.Application
End Sub
Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim prompt As String
prompt = "Are you sure you want to send " & Item.Subject & "?"
If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then
Cancel = True
End If
End Sub
在事件处理程序中,您可以签出属性,该属性允许设置一个Account
对象,该对象表示发送MailItem
的帐户。调用send方法时,SendUsingAccount
属性可用于指定应用于发送MailItem
的帐户
根据邮件项目上设置的帐户,您可能需要设置返回字符串的属性,该字符串指示邮件消息的预期发件人的显示名称。您可能需要取消默认操作并以编程方式重新提交项目。将文件夹树导航到“电子邮件地址”文件夹 这应该是
objMailItem.Parent.Parent
Private Sub-objinspector\u NewInspector(ByVal Inspector作为Inspector)
如果Inspector.currentItem.Class=olMail,则
设置objMailItem=Inspector.currentItem
如果objMailItem.Sent=False,则
Debug.Print objMailItem.Parent.Parent
如果InStr(LCase(objMailItem.Parent.Parent)、LCase(@domain.com)),那么
调用SetFromAddress(objMailItem)
如果结束
如果结束
如果结束
端接头
代码不是VBScript。如果有使用帐户的回复,请确认电子邮件地址也是帐户。在此窗口中运行ShowAllAccounts
code