【发布时间】:2019-04-30 07:05:57
【问题描述】:
我正在尝试在 R 中通过电子邮件发送 html 图片。首先我尝试使用以下代码发送图片
send_mail<-function(){
sender <- "asasa<support@aa.com>"
recipients <- c("aasb@aa.com", "asab@aa.com", "asb@aa.com")
send.mail(from = sender,
to = recipients,
subject = paste0("Send mail with image"),
body <- <html><img src="../img.png"></html>,
smtp = list(host.name = "XX", port = XX,
user.name = "XXX@gmail.com",
passwd = "XXX", ssl = TRUE),
authenticate = TRUE,
html = TRUE,
send = TRUE)
}
send_mail()
邮件已发送,但未显示图像。我再次搜索,然后决定使用base64嵌入图像,然后使用以下代码发送邮件
library(RCurl)
txt <- base64enc::base64encode("abc_2018-11-27.png")
html1 <- sprintf('<html><body><img src="data:image/png;base64,%s"></body></html>', txt)
send_mail<-function(){
sender <- "asasa<support@aa.com>"
recipients <- c("aasb@aa.com", "asab@aa.com", "asb@aa.com")
send.mail(from = sender,
to = recipients,
subject = paste0("Send mail with image"),
body <- html1,
smtp = list(host.name = "XX", port = XX,
user.name = "XXX@gmail.com",
passwd = "XXX", ssl = TRUE),
authenticate = TRUE,
html = TRUE,
send = TRUE)
}
send_mail()
因此,再次以 gmail 发送邮件,邮件正文中仅显示 base64 代码,而在 Outlook 中,只有一个图标丢失图像。
知道这里的问题是什么,或者我如何在邮件中发送 html 图像。图像在本地系统上。
【问题讨论】: