我正在尝试在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>")
)
Run Code Online (Sandbox Code Playgroud)
根据@lukeA的建议,这是最终的工作代码
library(mailR)
send.mail(from = "me@gmail.com",
to = "them@gmail.com",
subject = "Inline image example",
body = '<p>write text here</p>
<img src="R.PNG">
<p>more text here</p>',
html = TRUE,
inline = TRUE,
smtp = list(host.name = "<name here>"),
attach.files=c("R.png", "Project Description.xlsx"),
authenticate = FALSE)
Run Code Online (Sandbox Code Playgroud)