0

我一直在尝试使用 GmailR 包在一封电子邮件中发送 2 个图像(必须在邮件正文中添加这些图像)和 2 个附件(2 个 excel 文件),但到目前为止我还没有弄清楚。我已经查看了文档和这个小插图中的语法 - https://cran.r-project.org/web/packages/gmailr/vignettes/sending_messages.html

基于上面的小插图,我尝试了小插图(附件和图像部分)中提到的内容的组合,以在邮件正文中添加两个图像 + 两个单独的 xlsx 文件。当我尝试发送一张图像/一个附件(如小插图中所述)但无法拍摄多个图像/附件时,它工作得非常好。

#A. # From above mentioned vignette - (This works) - single attachment
email <- gm_mime() %>%
  gm_to('someaddress@somewhere.com') %>%
  gm_from("someaddress@somewhere.com") %>%
  gm_subject("Cars report") %>%
  gm_html_body(
    '<h1>A plot of <b>MotorTrend</b> data <i>(1974)</i></h1>
    <br><img src="cid:foobar">') %>%
  gm_attach_file("mtcars.png", id = "foobar")


#B. (This doesn't work) - more than one attachment? 
email <- gm_mime() %>%
  gm_to('xy@xy.com') %>%
  gm_from("xyz@gmail.com") %>%
  gm_subject(paste("Overview of Etc - ",today_date)) %>%
  gm_html_body(
    '<h1>Total Nos<b>XYZ</b> Region <i>(Year)</i></h1>
    <br><img src="cid:foobar"><img src="cid:foobar2">') %>%
  gm_attach_file(c("Overview1.jpeg","Overview2.jpeg"
,"file1.xlsx","file2.xlsx"), id = c("foobar1","foobar2"))

是否有任何人可以建议的解决方法?如果人们能指出我正确的方向,将不胜感激!

4

1 回答 1

0

事实证明,我们只需要再次输入子命令!

email <- gm_mime() %>%
  gm_to('xy@xy.com') %>%
  gm_from("xyz@gmail.com") %>%
  gm_subject(paste("Overview of Etc - ",today_date)) %>%
  gm_html_body(
    '<h1>Total Nos<b>XYZ</b> Region <i>(Year)</i></h1>
    <br><img src="cid:foobar"><img src="cid:foobar2">') %>%
  gm_attach_file("Overview1.jpeg", id = c"foobar1") %>%
  gm_attach_file("Overview2.jpeg", id = c"foobar2")%>%
  gm_attach_file("attach1.xlsx")%>%
  gm_attach_file("attach2.xlsx")

gm_send_message(email)
于 2020-10-30T10:51:20.460 回答