我正在尝试通过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图像。图像在本地系统上。
答案 0 :(得分:0)
只需更改
body <- <html><img src="../img.png"></html>,
到
body = paste0('<html><img src="../img.png"></html>'),
你有它