【问题标题】:Embedding an image in html email using R使用 R 在 html 电子邮件中嵌入图像
【发布时间】: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 图像。图像在本地系统上。

【问题讨论】:

    标签: html r email base64


    【解决方案1】:

    改变一下

        body <- <html><img src="../img.png"></html>,
    

        body = paste0('<html><img src="../img.png"></html>'),
    

    你有它

    【讨论】:

      猜你喜欢
      • 2011-10-06
      • 2015-03-14
      • 2020-12-14
      • 2016-11-06
      • 2017-07-04
      • 2011-07-12
      • 2010-12-23
      相关资源
      最近更新 更多