我的老板希望我下午 5 点后发给他的所有邮件在第二天早上 8 点送达。我能否在 Outlook 中将此设置为规则,这样我就不必每次都手动更改它?
答案1
ThisOutlookSession
好的。所以通过developer
标签输入visual basic
私人子版块会检查你老板的邮件to
(更改电子邮件,我认为它可能区分大小写)
如果是发给老板的,系统会运行检查时间并延迟的宏。我遇到了一些问题早上 8 点发送代码,你可能需要弄乱它。
Private Sub application_itemsend(ByVal item As Object, cancel As Boolean)
Dim myItem As mailItem
Set myItem = item
If myItem.Class = olMail And myItem.To = "[email protected]" Then
Call CheckSendTime
End If
End Sub
Public Sub CheckSendTime()
Dim myobj As Object
Dim myMail As mailItem
Dim WkDay As String
Dim MinNow As Integer
Dim SendHour As Integer
Dim SendDate As Date
Dim SendNow As String
'Set Variables
SendDate = Now()
SendHour = Hour(Now)
MinNow = Minute(Now)
WkDay = Weekday(Now)
SendNow = Y
'Check if after 5PM
If SendHour > 17 Then 'After 5 PM
SendHour = 34 - SendHour 'Send at 8 am next day
SendDate = DateAdd("h", SendHour, SendDate)
SendDate = DateAdd("n", -MinNow, SendDate)
SendNow = N
End If
'Send the Email
Set myobj = Application.ActiveInspector.CurrentItem
If TypeOf myobj Is Outlook.mailItem Then
Set myMail = myobj
'Check if we need to delay delivery
If SendNow = N Then
myMail.DeferredDeliveryTime = SendDate
End If
Else: myMail.Send
End If
End Sub
部分来源于这里
答案2
该解决方案与 Raystafarian 提出的解决方案基本相同,但逻辑简化。
使用方法:
1. 在 Outlook 中打开代码编辑器Alt+ F11。2
. 在 Project1 > Microsoft Outlook Objects 下双击 ThisOutlookSession
3. 将以下代码粘贴到编辑器中。4
. 根据需要修改电子邮件地址和时间范围。5
. 单击保存按钮并关闭代码编辑器窗口。6
. 更改 Outlook 宏安全性:单击文件 > Outlook 选项 > 信任中心。单击信任中心设置,然后单击宏设置并选择所有宏的通知
7. 重新启动 Outlook,并在出现提示时单击“启用宏”。
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim bossEmail As String
Dim delaySendAt As Date
Dim currentHour As Integer
bossEmail = "[email protected]"
delaySendAt = (Date + 1) & " 8:01:00 AM"
currentHour = Hour(Now())
' Delay emails sent between 5PM and 8AM
If currentHour >= 17 Or currentHour < 8 Then
' where To field contains boss's email address (case insensitive)
' but don't delay message sent to boss and other recipients
If InStr(1, Item.To, bossEmail, vbTextCompare) > 0 _
And InStr(Item.To, ";") = 0 Then
Item.DeferredDeliveryTime = delaySendAt
End If
End If
End Sub
符合指定条件的电子邮件将在单击“发送”按钮时进入发件箱文件夹,但要到指定时间才会发送。为了发送邮件,Outlook 应用程序必须在预定的发送时间运行。如果您从发件箱打开邮件,则必须再次单击“发送”,否则邮件将不会发送。