如何在Outlook中从R发送延迟发送的电子邮件?

问题描述

使用R中的RDCOMClient软件包,我从R发送了一系列自动电子邮件。电子邮件需要在特定的日期和时间发送,但是我无法弄清楚{{1}中的哪些元素}进行操作以发送延迟发送的电子邮件

这是我正在做的一个简单示例:

outMail

我尝试浏览MailModule对象列表here,但是找不到任何要使用的内容-我不确定如何检查上面创建的library(data.table) library(RDCOMClient) # table of emails,names and send times (stt) test_emails = data.table( First.Name = c("Joe","Brit","Anton"),email = c("[email protected]","[email protected]","[email protected]" ),stt = structure(c(1602270000,1603270000,1602470000),class = c("POSIXct","POSIXt"),tzone = "")) # access Outook OutApp <- COMCreate("outlook.application") # loop over table of names/emails for(i in 1:test_emails[,.N]){ #standard setup: outMail = OutApp$CreateItem(0) outMail$GetInspector() signature = outMail[["HTMLBody"]] outMail[["To"]] = test_emails[i,email] outMail[["subject"]] = "Subject line" # example body that prints the time and date of when the email is sent outMail[["HTMLBody"]] = paste0("<p>Hi ",test_emails[i,First.Name],",</p>","<p>As discussed please find attached the detailed test instructions (PDF) and data set (CSV file)","You received this email at ",gsub('^0','',format(econ_test[i,stt],'%I:%M %p')),' on ','%A,%B %d'),"</p>",'<p>',signature,'</p>') # sends right Now. How to delay this? outMail$Send() } 对象(例如, outMail不适用于此类对象。

谢谢。

***基于接受的答案的精确解决方案***

str()

解决方法

设置MailItem.DeferredDeliveryTime属性-https://docs.microsoft.com/en-us/office/vba/api/outlook.mailitem.deferreddeliverytime

您不需要MailModule对象。使用OutlookSpy(单击OutlookSpy功能区上的“项目”按钮)查看实时Outlook对象。

,

由于afaik Outlook需要运行(即在线并已连接)才能实现延迟交付,因此您的计算机也已启动并运行-为什么不使用taskscheduleR

来相应地计时R脚本>