13

I am trying to attach a file from my system to send it to an email id using R. I am using the gmailr package to send the mails. I have tried the following code for the same.

library(gmailr)

mime() %>%
to("abcd@gmail.com") %>%
from("xyz@gmail.com") %>%
text_body("My First Email using R.") -> first_part

first_part %>%
subject("Test Mail from R") %>%
attach_file("BazaarQueriesforURLData.txt") -> file_attachment

send_message(file_attachment)

I have been able to send text based messages but I am unable to send attachments from R. My attachment in the default directory folder only.I have seen many solutions on internet but I am unable to find a solution.

I would like to have a solution that has proper OAuth or Json based authentication as Google blocked my attempt to use smtp based authentication.

Kshitij Marwah
  • 1,091
  • 3
  • 14
  • 23
  • Do you have any possibility to get an error message? Can you show how the message looks before trying to send it? – Tholle Mar 18 '16 at 00:16
  • @Tholle I get a bounce message saying there was a error sending your mail. But when I look at my send items the attachment is there but it is not send to the user and instead I get a bounce message in my inbox saying "There was a error sending your mail". It is working fine with attachment. – Kshitij Marwah Mar 19 '16 at 07:38
  • I am unable to replicate this error with gmailr, package version 0.7.1.9000 - are you still having issues with this? – Stedy May 05 '16 at 03:11
  • @Stedy - I have not tried it for long. Will check and let you know. – Kshitij Marwah May 09 '16 at 09:26
  • @KshitijMarwah are you generating an application specific code for this Gmail account? I have found that I need to generate a specific password on Gmail for these kinds of scenarios. Does this account have two-step authentication enabled? – Matthew Crews Jan 17 '17 at 04:48
  • @MatthewCrews - Its only 1 step authentication.I am not sure of the specific password you are talking about. Can you tell me how to go about creating passwords for this. – Kshitij Marwah Jan 17 '17 at 16:29
  • @KshitijMarwah Here is what you need: https://support.google.com/accounts/answer/185833?hl=en – Matthew Crews Jan 17 '17 at 16:30

2 Answers2

1

Here's a tool in development:

# install.packages("devtools")

library(devtools)
install_github("gmailR", "trinker")

*if you use Windows, you'll need to use Rtools and devtools to install

doubleh2
  • 95
  • 9