使用mailR发送内联图像
我正在尝试将R创建的JPEG图像嵌入到电子邮件中,目的是创建一封自动的每日电子邮件,显示带有动态文本的图表。我能够附加图像,并指定身份证;但是,当我发送邮件并在Outlook中打开结果时,我会在图像应该位于的位置上打一个问号。该图像确实成功地附加到电子邮件,看起来该图像没有在HTML中内联呈现 以下是我的示例代码:使用mailR发送内联图像,r,email,sendmailr,R,Email,Sendmailr,我正在尝试将R创建的JPEG图像嵌入到电子邮件中,目的是创建一封自动的每日电子邮件,显示带有动态文本的图表。我能够附加图像,并指定身份证;但是,当我发送邮件并在Outlook中打开结果时,我会在图像应该位于的位置上打一个问号。该图像确实成功地附加到电子邮件,看起来该图像没有在HTML中内联呈现 以下是我的示例代码: library(mailR) send.mail(from = "xx@xxx.com", to = "xxx@xxx.com", subj
library(mailR)
send.mail(from = "xx@xxx.com",
to = "xxx@xxx.com",
subject = paste("Results for the date ending ", Sys.Date()-1, sep = ""),
body = '<html> Test image - <img src="cid:test_img.jpg" /></html>',
html = TRUE,
smtp = list(host.name = "xxx.xxx.com", user.name = "xxx@xxx.com", passwd = "xxx"),
attach.files = '/Users/xxx/Documents/Rplots/test_img.jpg',
authenticate = TRUE,
inline = TRUE,
send = TRUE)
库(mailR)
send.mail(发件人=”xx@xxx.com",
to=”xxx@xxx.com",
主题=粘贴(“结束日期的结果”,Sys.date()-1,sep=“”),
正文='测试图像-',
html=TRUE,
smtp=列表(host.name=“xxx.xxx.com”,user.name=”xxx@xxx.com“,passwd=“xxx”),
attach.files='/Users/xxx/Documents/Rplots/test_img.jpg',
验证=真,
inline=TRUE,
发送=真)
有什么想法吗?下面是一个有效的Gmail示例:
library(mailR)
png(file.path(getwd(), "..", "img.png")); plot(0); dev.off()
# Gmail users may have to switch https://www.google.com/settings/security/lesssecureapps before the send
send.mail(from = "...@gmail.com",
to = "...@gmail.com",
subject = "Subject of the email",
body = '<img src="../img.png">',
html = TRUE,
inline = TRUE,
smtp = list(host.name = "smtp.gmail.com",
port = 465,
user.name = "...",
passwd = "...",
ssl = TRUE),
authenticate = TRUE,
send = TRUE)
库(mailR)
png(file.path(getwd(),“.”,“img.png”);地块(0);发展主任()
#Gmail用户可能需要切换https://www.google.com/settings/security/lesssecureapps 发送前
send.mail(from=“…@gmail.com”,
至=“…@gmail.com”,
subject=“电子邮件的主题”,
正文=“”,
html=TRUE,
inline=TRUE,
smtp=list(host.name=“smtp.gmail.com”,
端口=465,
user.name=“…”,
passwd=“…”,
ssl=TRUE),
验证=真,
发送=真)
您必须引用前面提到的工作目录的相对路径,当然,还必须通过数据交换
…
它可能只是一个过滤器。电子邮件中有这么多的“xxx”,Outlook可能认为它是色情的,并且为了您自身的安全而阻止它。x只是为了掩盖我的实际电子邮件、密码等,所以它们实际上不在我的代码中。哦,我知道。但是,仅仅用文本传达笑话总是比较困难。啊,很抱歉:)酷——是的,这里的技巧是将本地路径添加到图像中作为源,而不是cid。我的最终HTML看起来像:。