我正在尝试使用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()任何帮助都是非常感谢的。
发布于 2017-08-12 04:44:19
这似乎是一个仍未解决的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()发布于 2019-03-21 10:03:29
你可以做两件事来改进它,既让它工作,又提高它的功能。首先,让它成为一个函数。其次,我已经成功地使用了'attach_part‘函数,但只有一次我第一次创建了’mim.‘。你也可以把这个函数去掉,然后简单地使用里面的代码。
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")https://stackoverflow.com/questions/45597560
复制相似问题