问题
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