2

我正在尝试将 R 创建的 JPEG 图像嵌入到电子邮件中,目的是创建一封自动显示的每日电子邮件,其中显示带有动态文本的图表。我能够附上图像,并指定竞争 ID;但是,当我发送消息并在 Outlook 中打开结果时,我会得到一个问号,图像应该在哪里。该图像确实成功地附加到了电子邮件,看起来图像只是没有在 HTML 中内联呈现。

这是我的示例代码:

library(mailR)

send.mail(from = "xx@xxx.com",
          to = "xxx@xxx.com",
          subject = paste("Results for the date ending ", Sys.Date()-1, sep = ""),
          body = '<html> Test image - <img src="cid:test_img.jpg" /></html>',
          html = TRUE,
          smtp = list(host.name = "xxx.xxx.com", user.name = "xxx@xxx.com", passwd = "xxx"),
          attach.files = '/Users/xxx/Documents/Rplots/test_img.jpg',
          authenticate = TRUE,
          inline = TRUE,
          send = TRUE)

关于发生了什么的任何想法?

4

1 回答 1

3

这是一个有效的 Gmail 示例:

library(mailR)
png(file.path(getwd(), "..", "img.png")); plot(0); dev.off()
# Gmail users may have to switch https://www.google.com/settings/security/lesssecureapps before the send
send.mail(from = "...@gmail.com",
          to = "...@gmail.com",
          subject = "Subject of the email",
          body = '<img src="../img.png">',
          html = TRUE,
          inline = TRUE,
          smtp = list(host.name = "smtp.gmail.com", 
                      port = 465, 
                      user.name = "...", 
                      passwd = "...", 
                      ssl = TRUE),
          authenticate = TRUE,
          send = TRUE)

您必须参考此处提到的工作目录的相对路径,并且 - 当然 -...通过您的数据进行交换。

于 2015-01-08T00:11:59.830 回答