【问题标题】:how to send html file in the body of the mail using R?如何使用 R 在邮件正文中发送 html 文件?
【发布时间】:2015-11-03 06:44:38
【问题描述】:

由于我的 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”文件,而不是直接在正文中。 显然我做错了什么,我在这个任务上苦苦挣扎了好几天,有人可以帮助我吗?

【问题讨论】:

  • 谢谢本杰明。我试过使用这个解决方案,因为我知道我需要将我的 html 文件包含到 html 代码中,这是我尝试这样做的方法: ... ...我也试过这个: 但是每次我收到的邮件都是空的。 data="./TEST2.html" 也给一个空邮件

标签: html r email sendmailr


【解决方案1】:

尝试使用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)

【讨论】:

  • 感谢您的回答,问题是我正在使用 Rstudio,无法安装库 mailR。我收到此消息:警告消息:包“mailR”不可用(适用于 R 版本 3.2.2)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多