跳至主要内容

如何在Outlook中自动回复包含原始邮件内容的邮件?

Author: Xiaoyang Last Modified: 2025-05-07

通常,当我们创建规则以自动回复外出邮件时,正文中不会包含原始邮件内容。那么,如何在Outlook中自动回复包含原始邮件内容的邮件呢?本文将介绍一种VBA代码,帮助您尽可能快速地完成此任务。

使用VBA代码在Outlook中自动回复包含原始邮件内容的邮件


使用VBA代码在Outlook中自动回复包含原始邮件内容的邮件

普通的Outlook规则无法帮助您完成此任务,但通过以下VBA代码,您可以快速轻松地完成它。请按照以下步骤操作:

1. 按住 ALT + F11 键打开 Microsoft Visual Basic for Applications 窗口。

2. 在 Microsoft Visual Basic for Applications 窗口中,双击 Project1(VbaProject.OTM) 窗格中的 ThisOutlookSession 以打开模块,然后将以下代码复制并粘贴到空白模块中。

VBA代码:自动回复包含原始邮件内容的邮件:

Public WithEvents xlItems As Outlook.Items
Private Sub Application_Startup()
    Set xlItems = Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub xlItems_ItemAdd(ByVal objItem As Object)
Dim xlReply As MailItem
Dim xStr As String
If objItem.Class <> olMail Then Exit Sub
Set xlReply = objItem.Reply
With xlReply
     xStr = "<p>" & "Hi, Your email has been received. Thank you!" & "</p>"
     .HTMLBody = xStr & .HTMLBody
     .Send
End With
End Sub 
the screenshot of step 1 about using vba to auto reply with original email message in Outlook

3. 然后保存并关闭代码窗口,关闭或重新启动Outlook以使VBA代码生效。现在,当您收到邮件时,Outlook将自动发送带有原始邮件内容的回复,如下图所示:

the screenshot of step 2 about using vba to auto reply with original email message in Outlook