在系统中没有outlook应用程序的情况下以R发送电子邮件



我可以使用以下代码发送电子邮件。

OutlookForSend = RDCOMClient::COMCreate("Outlook.Application")
emailToSend = OutlookForSend$CreateItem(0)
emailToSend[["subject"]] = "Subject"
emailToSend[["HTMLBody"]] = bodyToSend
emailToSend[["To"]] = "Email"
emailToSend$Send()

然而,我没有安装outlook,在服务器机器上,但仍然需要发送电子邮件。

我可以使用Python中的mailer包来实现同样的效果,在R.中实现同样效果的最佳方法是什么

感谢

在R中实现的任何SMTP客户端都将完成此任务。看看这个:Rmailer

从他们的例子来看:

library(Rmailer)

message <- c(
"Hey,",
"",
"I have a nice pic for you!",
"",
"Best",
"C."
)

settings <- list(
server = "smtp.example.org",
username = "user",
password = "password"
)

## send message:
sendmail(
from = "sender@example.org",
to = "receiver@example.org",
subject = "Good news!",
msg = message,
smtpsettings = settings,
attachment = "nice_pic.jpg"
)

使用mailR包解决了问题,效果很好。

library(mailR)
send.mail(from = "email@company.com",
to = "email@company.com",
subject = subjectToSend ,
body = bodyToSend,
html = TRUE,
smtp = list(host.name = "smtp.company.com", port = 25), 
send = TRUE)

相关内容

最新更新