1

我正在尝试触发带有规则的脚本以发送自动回复。

“您好,感谢您的来信,您的邮件已排入队列,您面前有XX封邮件,我们会尽快回复。”

XX 应该是未读电子邮件的数量。

我发现带有未读消息计数的 Outlook 自动回复

Private Sub myOlItems_ItemAdd(ByVal Item As Object)

End Sub

Sub AutoResponse(objmsg As Outlook.MailItem)

    ' define my reply message
    Dim objReply As MailItem
    ' let's get ourselves the inbox!
    Dim inbox As MAPIFolder
    Set inbox = Application.GetNamespace("MAPI"). _
    GetDefaultFolder(olFolderInbox)

    ' Let's get this reply going!
    Set objReply = objmsg.Reply
    ' Subject Re: their subject. Standard
    objReply.Subject = "Re: " & objReply.Subject
    ' Body - you define this, use the variable for the unread count in inbox
    objReply.Body = "Your email has been received. I currently have " & inbox.UnReadItemCount & " unread emails in my inbox and I will get yours as soon as I can"

    ' Send this thing!
    objReply.Send
    ' Reset
    Set objReply = Nothing

End Sub

它不起作用。

我在 Outlook 2016 上,使用交换邮件服务器。

4

2 回答 2

1

您需要在 Outlook 中手动创建规则并将 VBA 宏 sub ( AutoResponse) 分配给该规则。只有这样你才能运行代码。

作为一种可能的解决方法,您可以处理在收件箱中收到新项目时触发的应用程序的NewMailEx事件。当新邮件到达收件箱并且在客户端规则处理发生之前触发该事件。您可以使用 EntryIDCollection 数组中返回的条目 ID 来调用NameSpace.GetItemFromID方法并处理该项目。有关详细信息,请参阅Outlook 的规则和警报:运行脚本

对于具有 Exchange Server 帐户(非缓存 Exchange 模式或缓存 Exchange 模式)的用户,该事件将仅针对 Outlook 启动后到达服务器的邮件触发。对于在 Outlook 启动后立即在缓存 Exchange 模式下同步的邮件,以及在 Outlook 在非缓存 Exchange 模式下启动时已经在服务器上的邮件,不会触发该事件。

于 2017-05-09T12:08:04.860 回答
1

您的Items.ItemAdd 事件设置不正确,请尝试没有 Outlook 规则的流动代码,确保重新启动 Outlook

Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
    Dim olNs As Outlook.NameSpace
    Dim Inbox  As Outlook.MAPIFolder

    Set olNs = Application.GetNamespace("MAPI")
    Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
    Set Items = Inbox.Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)

    If TypeOf Item Is Outlook.mailitem Then
        AutoResponse Items
    End If

End Sub

Private Sub AutoResponse(Item As Outlook.mailitem)
    Dim Reply As Outlook.mailitem ' Reply msg
    Dim Inbox As Outlook.MAPIFolder ' Inbox

    Set Inbox = Application.GetNamespace("MAPI") _
                .GetDefaultFolder(olFolderInbox)

    ' Let's get this reply going!
    Set Reply = Item.Reply
    ' Subject Re: their subject. Standard
    Reply.subject = Reply.subject

    ' Body - you define this, use the variable for the unread count in inbox
    Reply.HTMLBody = "Your email has been received. I currently have " & _
                      Inbox.UnReadItemCount & _
              " unread emails in my inbox and I will get yours as soon as I can"

    ' Send this thing!
    Reply.Send
    ' Reset
    Set Reply = Nothing

End Sub
于 2017-05-10T20:06:22.537 回答