在系统中没有 outlook 应用程序的情况下在 R 中发送电子邮件
Sending emails in R without outlook app in the system
我可以使用以下代码发送电子邮件。
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)
我可以使用以下代码发送电子邮件。
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)