-
Notifications
You must be signed in to change notification settings - Fork 56
Description
Summary of the bug
When trying to send messages with text+html body and .txt or .pdf attachments, gm_send_message() and gm_send_draft() are dropping some MIME parts from the message:
- in case there is a .txt attachment, the text of the message is dropped when sending ("text/plain" & "text/html" MIME parts are missing)
- in case there is a .pdf attachment, the attachment is dropped when sending ("application/pdf" MIME part is missing)
Some other file extensions are affected too by such problem: see bug #81 which was open in 2017 but has been closed by mistake in 2019 while in fact the bug was not resolved.
This bug is observed with gmailr 2.0.0 but was apparently already present in previous versions (see bug #81).
Code for reproducing the bug
# Main email message's elements
email_recipient = "...@..." # /!\ enter a valid test email address here /!\
email_sender = "me"
email_subject = "Test message without attachment"
email_subject_txt = "Test message with txt attachment"
email_subject_pdf = "Test message with pdf attachment"
email_text_body = "Hello,\n\nhere attached is your file!\n\nBest regards,\n\nMe"
email_html_body = "<div dir=ltr>Hello,<br><br>here attached is <b>your file</b>!<br><br>Best regards,<br><br>Me</div>"
# Creating a .txt file
txt_filename <- tempfile(fileext=".txt")
writeLines("This is a .txt file\nplease help solving this bug!\nBla bla bla,\nbla bla bla", txt_filename)
# Creating a .pdf file
pdf_filename <- tempfile(fileext=".pdf")
pdf(pdf_filename)
plot(c(1:10),c(1:10)); text(1,10,"This is a basic PDF file", pos=4)
dev.off()
# Creating MIME email messages
msg_basic <- gm_mime() |> # basic without attachment
gm_from(email_sender) |>
gm_to(email_recipient) |>
gm_subject(email_subject) |>
gm_text_body(email_text_body) |>
gm_html_body(email_html_body)
msg_with_att_txt <- msg_basic |> # same with .txt attachment
gm_subject(email_subject_txt) |>
gm_attach_file(txt_filename)
msg_with_att_pdf <- msg_basic |> # same with .pdf attachment
gm_subject(email_subject_pdf) |>
gm_attach_file(pdf_filename)
# Sending MIME email messages directly
gm_send_message(msg_basic) # The message is correctly sent with its 2 MIME parts ("text/plain" & "text/html")
gm_send_message(msg_with_att_txt) # /!\ BUG /!\: the message is sent but only with the .txt attachment (missing "text/plain" & "text/html" MIME parts)
gm_send_message(msg_with_att_pdf) # /!\ BUG /!\: the message is sent but missing its attachment (missing "application/pdf" MIME part)
# Creating draft email messages
draft_richId_basic <- gm_create_draft(msg_basic) # The draft is correctly created in the gmail draft folder
draft_richId_with_att_txt <- gm_create_draft(msg_with_att_txt) # The draft is correctly created in the gmail draft folder
draft_richId_with_att_pdf <- gm_create_draft(msg_with_att_pdf) # The draft is correctly created in the gmail draft folder
# Sending draft email messages
gm_send_draft(draft_richId_basic) # The message is correctly sent with its 2 MIME parts ("text/plain" & "text/html")
gm_send_draft(draft_richId_with_att_txt) # /!\ BUG /!\: the message is sent but only with the .txt attachment (missing "text/plain" & "text/html" MIME parts)
gm_send_draft(draft_richId_with_att_pdf) # /!\ BUG /!\: the message is sent but missing its attachment (missing "application/pdf" MIME part)
Partial workaround
Draft messages with attachment created with gm_create_draft() can be sent manually from Gmail's web client and this works fine. The bug is only when sending them from R with gm_send_draft(), or when sending them directly with gm_send_message().