gmailr text_body不包括在内

时间:2017-08-09 17:53:47

标签: r gmail-api

我正在尝试使用gmailr发送电子邮件,电子邮件发送正常,但“text_body()”中包含的正文已丢失。

当我删除attach_file()时它会起作用。

mime() %>%
  to('email@email.com') %>%
  from('email@email.com') %>%
  subject(paste(Sys.Date()," Subject", sep = '')) %>%
  text_body('Body') %>%
  attach_file(paste(Sys.Date(),"Attachment.csv", sep = '')) %>%
  send_message()

感谢任何帮助。

2 个答案:

答案 0 :(得分:1)

这似乎是known bug仍未解决。

可能的workaround是第二次使用attach_part包含身体,如下所示:

mime() %>%
  to('email@email.com') %>%
  from('email@email.com') %>%
  subject(paste(Sys.Date()," Subject", sep = '')) %>%
  text_body('Body') %>%
  attach_part('Body') %>%
  attach_file(paste(Sys.Date(),"Attachment.csv", sep = '')) %>%
  send_message()

答案 1 :(得分:0)

您可以做两件事来改进它,以使其起作用并改善其功能。首先,使其具有功能。其次,我使用'attach_part'函数取得了成功,但是只有当我第一次制作'mime'时才如此。您也可以删除该功能,而只需使用代码。

msg <- "your message goes here"

prepare_and_send <- function(sender, recipient,
                             title, text,
                             attachment) {
  email <- mime() %>%
    to(recipient) %>%
    from(sender) %>%
    subject(title) %>%
    html_body(text) %>%
    attach_file(attachment, type = "html")
  email <- attach_part(email, msg) %>%
    send_message() 
}

# Put the above function to use.
prepare_and_send("sender@gmail", "to@gmail", "some subject",
                 "some text", "20558.html")