add_attachment in blastula R package

无人久伴 提交于 2020-12-15 06:51:55

问题


How can I sent an attachment in blastula.

correo <- compose_email(
  body = md("Tarea_01"))
correo %>% add_attachment(file = "emilia/tarea_01/liquenes.csv", filename = "liquenes")
correo %>%
  smtp_send(
    from = "xxxxxx@gmail.com",
    to = "xxxxxxx@gmail.com",
    subject = "Tarea_01",
    credentials = creds_key(id = "gmail")
  )

I can send the email but there is no attachment in received email.

Any clue why there is no attachment?

Manuel


回答1:


The add_attachments() function didn't work for me. I "de-functionized" it and could get it to send an attachment.

file = paste0(source_path, "current.html")
content_type = mime::guess_type(file)
filename = basename(file)

expanded_path <- file %>% path.expand() %>% normalizePath(mustWork = TRUE)
attachment_list <- list(file_path = expanded_path, content_type = content_type, 
                    disposition = "attachment", filename = filename)
email$attachments <- c(email$attachments, list(attachment_list))

Where "file" is the complete path to the attachment. Took code directly out of function and it worked. Could not figure out why function wouldn't.




回答2:


Just stumbled over this older question - I believe the problem is in in your second code block

correo %>% add_attachment(file = "emilia/tarea_01/liquenes.csv", filename = "liquenes")

is actually not changing correo, you have to reassign it or directly proceed with the pipe, e.g.

correo %>% 
  add_attachment(file = "emilia/tarea_01/liquenes.csv", filename = "liquenes") %>%
  smtp_send(
    from = "xxxxxx@gmail.com",
    to = "xxxxxxx@gmail.com",
    subject = "Tarea_01",
    credentials = creds_key(id = "gmail")
  )

With this setup I don´t have problems with attaching something.



来源:https://stackoverflow.com/questions/61825694/add-attachment-in-blastula-r-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!