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

Body is blank after attaching file #60

Closed
Vestaxis opened this issue Apr 13, 2016 · 10 comments
Closed

Body is blank after attaching file #60

Vestaxis opened this issue Apr 13, 2016 · 10 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@Vestaxis
Copy link

I haven't actually come across an example which does this but I was hoping that this would work:
write.csv(file = "iris.csv", iris)

mime() %>%
to('someaddress@somewhere.com') %>%
from("someaddress@somewhere.com") %>%
subject("Test subject") %>%
text_body("Test body") %>%
attach_file("iris.csv") %>%
send_message()

Although the email is sent with the attachment, the body is not included in the email. It seems to be dropped entirely from the message when it's sent although the object that goes into send_message() still includes the body part. It doesn't work with html_body() either, attaching multiple files works fine.

This email does include the body:

mime() %>%
to('someaddress@somewhere.com') %>%
from("someaddress@somewhere.com") %>%
subject("Test subject") %>%
text_body("Test body") %>%
#attach_file("iris.csv") %>%
send_message()

@puterleat
Copy link

I have this issue too... I also find that I can't send both text and html body parts.

@shihs
Copy link

shihs commented Jun 30, 2016

I got the same problem...
Do you guys have any method to solve this problem?

@jrfarrer
Copy link

I have the same issue and haven't figured out a solution yet.

@jonspring
Copy link

I had some luck using the format below. For some reason taking out either the html_body or the attach_part terms would hide the text.

html_msg <- mime() %>%
to("emails@foo.com") %>%
from("emails@bar.com") %>%
subject(email_subject) %>%
html_body(body_text) %>%
attach_part(body_text) %>%
attach_file(attachment) -> file_attachment

@CarlBoneri
Copy link

It would seem like there are duplicated fields generated from the mime construction, so it's last-in first-out as far as the request is concerned... thus dropping any body info related to a message. @jonspring 's solution works nicely.

@nfrimando
Copy link

If the message was html, it would still appear as text though. Is there any way to send html along with an attachment?

@smithjd
Copy link

smithjd commented Jan 25, 2018

I'm trying to send 2 attachments. Getting them both in the one email is more important than getting the body to show nicely (or at all). Here is the only combination of calls that I could get to work:

 body_text <-  "Here are the weekly  reports."

test_email <- mime(
  To = gmail_to_list,
  From = my_address,
  Subject = paste("Weekly reports as of", today()),
  html_body = body_text ) %>%
  attach_part(body_text) %>% 
  attach_file("past_meetings_report.html", type = "html") %>%
  attach_file("scheduled_meetings_report.html", type = "html")

send_message(test_email)

At some point I managed to send an HTML body and one attachment, but the HTML didn't render. So this seems to be a very fragile interface.

@IoannisM13
Copy link

IoannisM13 commented Sep 22, 2018

Hello all,

Newbie to R so please be patient with my comment. I am trying to simply attach a csv file in a message, so that the receiver can download as it is and use.

Is this possible with gmailR?

Thank you

@vedutkarsh
Copy link

vedutkarsh commented Mar 1, 2019

If the message was html, it would still appear as text though. Is there any way to send html along with an attachment?

@nfrimando

There seems to be a nice workaroud 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@foo.com") %>% to (email@bar.com) %>%
subject("Subject") %>% html_body("") %>%
attach_file("/home/email.body.html") %>%
attach_file("main_file.xlsx" )

send_message(email)

Note:- Through trial and errors it appears that any arbitrary argument needs to be passed to the 'html_body()' without which this wouldn't work. Hence the empty quotes there.

@jimhester jimhester added the bug an unexpected problem or unintended behavior label Aug 13, 2019
@jimhester
Copy link
Member

This is now fixed without workarounds

pkgload::load_all("~/p/gmailr")
#> Loading gmailr
write.csv(iris, "iris.csv")
gm_mime() %>%
  gm_from("email@foo.com") %>%
  gm_to("email@bar.com") %>%
  gm_subject("I bought you") %>%
  gm_text_body('Some flowers!') %>%
  gm_attach_file("iris.csv") %>%
  gm_create_draft()
#> Draft Id: r-2808894807153655050 
#> Thread Id: 16cab9f58efda151

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

Screen Shot 2019-08-19 at 4 44 24 PM

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