将文件附加到 gmailr 中的 MIME 对象
Attach files to MIME object in gmailr
在尝试将文件附加到信件时,我正在努力定义正确的 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--
我做错了什么?
这里讨论这个问题:
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)
此处进行以下讨论:here 现在已修复。
您需要将 gmailr 更新到版本 1.0.0 及更高版本,然后 更新 您的代码,如下所示
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()
很多函数名都变了,只加了'gm_'(比如mime
现在变成了gm_mime
)但是要注意鉴权,这些函数变的比较多。
在尝试将文件附加到信件时,我正在努力定义正确的 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--
我做错了什么?
这里讨论这个问题:
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)
此处进行以下讨论:here 现在已修复。 您需要将 gmailr 更新到版本 1.0.0 及更高版本,然后 更新 您的代码,如下所示
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()
很多函数名都变了,只加了'gm_'(比如mime
现在变成了gm_mime
)但是要注意鉴权,这些函数变的比较多。