【发布时间】:2016-02-22 06:52:02
【问题描述】:
我正在尝试在 R 中发送一封带有 2 个附件的电子邮件,其中一个是我想内联显示的图片
我可以成功发送带有两个附件的电子邮件,但我一直卡在内联显示它方面。
任何想法将不胜感激
当前代码:
setwd(<filepath>)
library(sendmailR)
library(png)
##### SET BASIC EMAIL CHARACTERISTICS
from <- "me@gmail.com"
to <- "them@gmail.com"
subject <- "Sales report"
##### PREPARE ATTACHMENT
# put the body and the mime_part in a list for msg
# x = needs full path if not in working directory
# name = same as attachmentPath if using working directory
attachmentObject <- mime_part(x="spreadsheet.xlsx",name="spreadsheet.xlsx")
attachmentObject2 <- mime_part(x="graph.png",name="graph.png")
body <- c("Generic body text", <graph attachmentObject2>)
bodyWithAttachment <- list(body,attachmentObject,attachmentObject2)
##### SEND EMAIL
sendmail(from=from,
to=to,
subject=subject,
msg=bodyWithAttachment,
control=list(smtpServer="<server name>")
)
【问题讨论】:
-
要么使用
mailR包,请查看example。或者对你的图片进行base64编码并将其放入<img src="...">。 -
@lukeA 感谢您的快速回复!两个问题: 1. 如果我使用 mailR 包,它会将我的整个电子邮件转换为 HTML,并且附件必须是 html,而不是 .xlsx。那准确吗? 2. 如果我使用 选项,那仍然是 HTML 吗?