如何设置 Outlook 在夜间发送自动回复?

如何设置 Outlook 在夜间发送自动回复?

我正在使用 Microsoft Outlook 2016 Home。我想为当地时间 22:00 至 08:00 之间收到的所有电子邮件设置“外出”自动回复。

我知道我需要使用一个脚本来实现这一点。我发现这个脚本可以在白天自动回复 15:00 之前收到的电子邮件。这个脚本运行良好,所以我尝试将其改为在晚上运行,回复 22:00 至 08:00 之间收到的电子邮件。

原始脚本在这里:如何设置 Outlook 每天在特定时间发送自动回复?

我修改后的脚本在这里:

Public Sub Check_ReceivedTime(newMail As Outlook.MailItem)

    Dim obj As Object
    Dim ReceivedHour As Integer
    Dim newReply As MailItem
    Dim msg As String

    ReceivedHour = Hour(newMail.ReceivedTime)

    If ReceivedHour >= 22 OR ReceivedHour < 8 Then
        Set newReply = newMail.reply
        msg = "This is the email body text..."

        CreateMail newReply.To, msg
    Else
        Debug.Print "During office hours. Do not sent the automated reply."
    End If

    Set newReply = Nothing
End Sub


Private Sub CreateMail(ReplyAddress As String, msg As String)

    Dim objMail As Outlook.MailItem

    Set objMail = CreateItem(olMailItem)

    With objMail
        .To = ReplyAddress
        .Body = msg

        .Display
        ' or
        ' .Send
    End With
End Sub

我怀疑 12/24 小时格式可能存在问题,但我自己无法解决这个问题。有人能帮我吗?

答案1

如果原始代码产生奇怪的结果,则可能存在另一种选择。

Option Explicit

Public Sub Check_ReceivedTime_SenderEmailAddress(newMail As MailItem)

Dim objMail As MailItem
Dim ReceivedHour As Integer
Dim msg As String

ReceivedHour = Hour(newMail.ReceivedTime)

If ReceivedHour >= 22 Or ReceivedHour < 8 Then

    Set objMail = CreateItem(olMailItem)
    msg = "This is the email body text..."

    With objMail

        ' The sender may have set up a replyTo address
        '  which is now ignored
        ' https://www.lifewire.com/replies-go-to-different-address-outlook-1173678

        .To = newMail.SenderEmailAddress
        .Body = msg
        .Display
        ' or
        ' .Send

    End With

Else

    Debug.Print "During office hours. Do not sent the automated reply."

End If

End Sub

相关内容