【问题标题】:Attach files to MIME object in gmailr将文件附加到 gmailr 中的 MIME 对象
【发布时间】:2017-10-10 17:33:24
【问题描述】:

在尝试将文件附加到字母时,我正在努力定义正确的 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--

我做错了什么?

【问题讨论】:

  • 好吧,即使mime::guess_type() 也无法解决问题

标签: r gmail gmail-api mime


【解决方案1】:

这里讨论这个问题:

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)

【讨论】:

  • 这个“几乎”对我有用:附件在那里,但正文/味精没有出现
【解决方案2】:

以下讨论: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)但是注意身份验证,这些函数改变得更多。

【讨论】:

    猜你喜欢
    • 2018-05-21
    • 2020-04-12
    • 2014-07-04
    • 1970-01-01
    • 2019-06-08
    • 1970-01-01
    • 2013-03-14
    • 2012-06-03
    • 1970-01-01
    相关资源
    最近更新 更多