由于我的Rmarkdown代码,我有一个html文件。现在我需要直接在电子邮件正文中发送一封包含此html文件的电子邮件,而不是在附件中。我正在尝试这篇文章的解决方案:"send HTML email using R" post 但它似乎只适用于html文本而不是html文件。 这就是我试图做的事情:
library(sendmailR)
from<-"<sender@enterprise.lan>"
to<-c("<reciever@enterprise.com>")
message ="./TEST.html"
subject = "Test HTML"
msg <- mime_part(message)
msg[["headers"]][["Content-Type"]] <- "file/html"
sendmail(from, to, subject, msg = msg,control=list(smtpServer="localhost"),headers=list("Content-Type"="file/html; charset=UTF-8; format=flowed"))
此试用版向我发送了一封电子邮件,但附有“TEST.html”文件,而不是直接在正文中。 显然我做错了,我几天都在为这项任务苦苦挣扎,有人可以帮帮我吗?
答案 0 :(得分:0)
尝试使用mailR
包轻松发送HTML格式的电子邮件,如下所示:
send.mail(from = "sender@gmail.com",
to = c("recipient1@gmail.com", "recipient2@gmail.com"),
subject = "Subject of the email",
body = "<html>The apache logo - <img src=\"http://www.apache.org/images/asf_logo_wide.gif\"></html>", # can also point to local file (see next example)
html = TRUE,
smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "gmail_username", passwd = "password", ssl = TRUE),
authenticate = TRUE,
send = TRUE)