I have multiple lists which look like this:
list(structure(list(mail = c("[email protected]", "[email protected]", "[email protected]",
"[email protected]", "[email protected]", "[email protected]", "[email protected]"), file = c("file1.pdf",
"file2.pdf", "file3.pdf", "file4.pdf", "file5.pdf", "file6.pdf",
"file7.pdf")), row.names = c(NA, 7L), class = "data.frame"))
As you can see, it's the same email but with multiples files associated to it. So what I want is to attach all this files at once when I create a draft considering that for every email, the number of files won't be the same. Since that can't be done directly with gm_attach_file() i'm trying to use purrr::reduce().
When I execute:
files_vector <- data.frame(arc= test[[1]][[2]])
purrr::reduce(.x = files_vector, .f = gm_attach_file)
I get all the files I want to send:
[1] "file1.pdf" "file2.pdf" "file3.pdf" "file4.pdf" "file5.pdf" "file6.pdf" "file7.pdf"
I must say that:
files_vector <- data.frame(arc= test[[1]][[2]])
doesn't work with my original data since I got this error:
Error in mime$parts : $ operator is invalid for atomic vectors
When I run the whole code for creating an email, I just got an empty draft with no recipient and no attached files at all.
gm_mime()|>
gm_to(sprintf("%s", unique(test[[1]][[1]])))|>
gm_from("[email protected]") |>
gm_subject("The files you requested")|>
gm_html_body(body = paste(glue::glue(
"<h5><b> <b></h5>
<p>
<p> </p>
<p> .</p>"
)))|>
purrr::reduce(.x = files_vector, .f = gm_attach_file)|>
gm_create_draft()
I don't know if I'm doing something wrong or it's simply that gmailr is somewhat limited on how many files you could attach to an email. Any feedback will be much appreciated.
I must add that I also reviewed this: How to send multiple attachments and images(in mail) body using GmailR package? and the solution it's given there doesn't work at all.