gpt4 book ai didi

r - 通过电子邮件发送内嵌图像 R

转载 作者:行者123 更新时间:2023-12-02 03:21:23 25 4
gpt4 key购买 nike

我正在尝试在 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>")
)

最佳答案

根据 @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)

关于r - 通过电子邮件发送内嵌图像 R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33815591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com