Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html body is not being sent together with attachment #81

Closed
MST2803 opened this issue Aug 16, 2017 · 12 comments
Closed

html body is not being sent together with attachment #81

MST2803 opened this issue Aug 16, 2017 · 12 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@MST2803
Copy link

MST2803 commented Aug 16, 2017

I want to send an attachment and write a message. Somehow it does not send the text. What I am doin' wrong?

text_content <- "Can you see that?"

html_msg = mime() %>%
to(send_to) %>%
from(send_from) %>%
html_body(text_content) %>%
subject(sb_to) %>%
attach_file(pathfile)
send_message(html_msg)

@dyrland
Copy link

dyrland commented Mar 1, 2018

Right before I use attach_file I use attach_part(text_content) (or whatever your html_body is) and it works fine for me.

@aedobbyn
Copy link

Adding attach_part() before attach_file() does allow you to include both an html_body and an attachment but it doesn't render the html, for me.

library(gmailr)
library(ggplot2)
library(here)
library(xtable)

email <- "your_email"

gmail_auth()

ggplot(mtcars) +
  geom_point(aes(carb, mpg))
ggsave(filename = here("plt.png"), device = "png")

msg_body <- print(xtable(mtcars), type="html")

msg <- 
  mime() %>%
  to(email) %>%
  from(email) %>% 
  html_body(msg_body) %>%
  attach_part(msg_body) %>%
  attach_file(here("plt.png"))

send_message(msg)

Without attach_part, it seems you can either have an html_body or an attachment but not both.

I'm using the CRAN version 0.7.1 on R 3.5.0.

@jimhester jimhester added the bug an unexpected problem or unintended behavior label Aug 22, 2018
@sanjmeh
Copy link

sanjmeh commented Mar 24, 2019

Was this bug removed (of either being able to send attachment or body text but not both together).

@sanjmeh
Copy link

sanjmeh commented Mar 24, 2019

@aedobbyn while your suggested sequence

 mime() %>%
 to(email) %>%
 from(email) %>% 
 html_body(msg_body) %>%
 attach_part(msg_body) %>%
 attach_file(here("plt.png"))

works but it will only work if msg_body is plain text.
Also it fails if subject() helper is also included.

Is there any other recommended sequence for adding the following also?

  1. Subject
  2. HTML body
  3. Attachment

@sanjmeh
Copy link

sanjmeh commented Mar 26, 2019

@jimhester : please can you update us what happened to this bug fix? There aren't many packages in R with gmail API wrapper functions. It would be very nice if the gmailR package is actively maintained. Hoping for some response. Otherwise the gmailR package is excellent.

@sanjmeh
Copy link

sanjmeh commented Mar 30, 2019

I find that gmailR has some other bugs. Am raising them as separate issues. Kindly add a line to the above so we get some confidence that the R community is working. gmailR is a very important package to be left out without support.

@sea0ttle
Copy link

sea0ttle commented May 3, 2019

@jimhester - piggybacking on @sanjmeh 's request for an update above. Love this package and this bug fix would add a ton of value.

@vedutkarsh
Copy link

There seems to be a nice workaround to get the HTML outputs too. All you need to do is attach_file() the .html along with the attachment.

Following format works for me.

email <-
mime() %>% from("[email protected]") %>% to ([email protected]) %>%
subject("Subject") %>% html_body("") %>%
attach_file("/home/email.body.html") %>%
attach_file("main_file.xlsx" )

send_message(email)

It appears that any argument needs to be passed to the 'html_body()' without which this wouldn't work. Hence the empty quotes there.

@jimhester
Copy link
Member

This is now fixed without workarounds

write.csv(iris, "iris.csv")
gm_mime() %>%
  gm_from("[email protected]") %>%
  gm_to("[email protected]") %>%
  gm_subject("I bought you") %>%
  gm_html_body('Some <b style="color:DARKVIOLET">flowers</b>!') %>%
  gm_attach_file("iris.csv") %>%
  gm_create_draft()
#> Draft Id: r-8123784243409940905 
#> Thread Id: 16cab9854293de54

Created on 2019-08-19 by the reprex package (v0.3.0)

Screen Shot 2019-08-19 at 4 37 08 PM

@sanjmeh
Copy link

sanjmeh commented Aug 20, 2019

That's great news. when is the update going on CRAN?

@FrancoisR95
Copy link

FrancoisR95 commented Feb 10, 2025

@jimhester I'm sorry but unfortunately this is NOT FIXED at all :
in gmailr 2.0.0, gm_send_message() has still got the same bug as described by @MST2803 in 2017 when opening this bug.

If I attach a .txt file to the gmailr MIME message, using gm_attach_file(), then gm_send_message() will send only this text attachment, without the text body and without the html body.

@jimhester, you gave a partial workaround, which consists in creating a draft. Yes, gm_create_draft() works properly indeed. And then it's possible to send the draft manually from Gmail.
But when trying to send the created draft from R with gm_send_draft(), unfortunately the same bug occurs as with gm_send_message(): only the text attachment is sent, without the text body and without the html body!

There is also a similar bug with .pdf attachments, but with different behavior:
.pdf attachments are correctly handled by gm_create_draft() however gm_send_message() and gm_send_draft() both ignore them when sending the message (no .pdf attachment is sent).

Could someone reopen this bug which has been mistakenly closed? Many thanks

@FrancoisR95
Copy link

I explained the cause of this bug in #202, and gave there a workaround. I hope that this will be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

8 participants