Send a email with Attachment in R using Gmail

Viewed 3087

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.

2 Answers
Related