others - 如何使用VBA从Outlook收件箱自动延迟发送电子邮件?

我是VBA方面的新手,我想创建一个规则(脚本),该规则可以自动转发在Outlook收件箱中接收到的电子邮件,并且指定延迟的时间?

我试过:


Public Declare Sub Sleep Lib"kernel32" (ByVal dwMiliseconds As Long) 


Sub send(Item As Outlook.MailItem) 


Set fwd = Item.Forward 


fwd.Recipients.Add"mail@email.com" 


Sleep (10000) 


fwd.send 


End Sub



还尝试了:


Sub WasteTime(Finish As Long)



 Dim NowTick As Long


 Dim EndTick As Long



 EndTick = GetTickCount + (Finish * 1000)



 Do



 NowTick = GetTickCount


 DoEvents



 Loop Until NowTick> = EndTick



End Sub



Sub send(Ite As Outlook.mailItem)


 Set fwd = Item.Forward


 fwd.Recipients.Add"mail@email.com"


 WasteTime (10)


 fwd.send


 End Sub



无效果。

第二个代码实际上冻结了我的整个 Outlook 应用程序,这不是我想要的效果。 我只想推迟发送邮件。

时间:

尝试使用 DeferredDeliveryTime属性设置发送邮件的时间。

例子


Option Explicit


Public Sub Example()


 Dim Item As Outlook.MailItem



 Set Item = Application.CreateItem(0)



 With Item


. Subject ="test"


. To ="0m3r"


. DeferredDeliveryTime = DateAdd("n", 10, Now)


 Debug.Print Item.DeferredDeliveryTime


. Send


 End With



 Set Item = Nothing


End Sub



函数


DateAdd("n", 10, Now)



+--------+-----------------+


| Value | Explanation |


+--------+-----------------+


| yyyy | Year |


| q | Quarter |


| m | Month |


| y | Day of the year |


| d | Day |


| w | Weekday |


| ww | Week |


| h | Hour |


| n | Minute |


| s | Second |


+--------+-----------------+



...