我在尝试将文件附加到字母时努力定义适当的mime类型。我用png-image测试了这个功能但最终我需要附上一个pdf。
library(gmailr)
test_email <- mime(
To = "mymail@yandex.ru",
From = sender_account,
Subject = "this is just a gmailr test",
body = "Can you hear me now?") %>%
attach_file(file = "health.png", type = "image/png")
send_message(test_email)
得到这样的东西而不是附加文件:
Can you hear me now? --29c4c91341434848f627ac9c696d9ed9--
我做错了什么?
答案 0 :(得分:3)
这个问题在这里讨论:
https://github.com/jimhester/gmailr/issues/60
如果主体仍然包含--numbers--字符串是可以接受的,则以下解决方案对我有用:
import(gmailr)
msg <- "This is the message body.\n\n"
email <- mime(
To = "to@domain.com",
From = "from@domain.com",
Subject = "Important subject",
body = msg)
email <- attach_part(email, msg)
email <- attach_file(email, file = "att1.txt", type = "text/plain")
email <- attach_file(email, file = "att2.txt", type = "text/plain")
email <- attach_file(email, file = "att3.pdf", type = "application/pdf")
send_message(email)
答案 1 :(得分:1)
以下讨论:here现在已解决。 您需要将gmailr更新到1.0.0及更高版本,并像这样
更新代码
s
许多功能名称仅通过添加'gm_'进行了更改(例如,pkgload::load_all("~/p/gmailr")
write.csv(iris, "iris.csv")
gm_mime() %>%
gm_from("email@foo.com") %>%
gm_to("email@bar.com") %>%
gm_subject("I bought you") %>%
gm_text_body('Some flowers!') %>%
gm_attach_file("iris.csv") %>%
gm_create_draft()
现在为mime
),但是要注意身份验证,这些功能的更改要多得多。