1

I am simply trying to send an email with R through my gmail account using the mailR package but it does not seem to work.

I get this error:

Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl,  : 
  org.apache.commons.mail.EmailException: Sending the email to the following server failed : aspmx.l.google.com:25

Below is the code with anonymized gmail adresses.

install.packages("mailR")
library(mailR)
sender <- "sender@gmail.com"  # Replace with a valid address
    recipients <- c("receiver1@gmail.com")  # Replace with one or more valid addresses
    email <- send.mail(from = sender,
                       to = recipients,
                       subject="Subject of the email",
                       body = "Body of the email",
                       smtp = list(host.name = "aspmx.l.google.com", port = 25),
                       authenticate = FALSE,
                       send = FALSE)


    email$send() # execute to send email
ML_Enthousiast
  • 1,147
  • 1
  • 15
  • 39
  • Are you sure you have the server right? Perhaps off topic, but can you get it working directly from Java? – Tim Biegeleisen Dec 10 '17 at 11:01
  • Hi, I am not able to answer your questions, how can I check all this? Are you asking if the host name is the correct one? – ML_Enthousiast Dec 10 '17 at 13:02
  • Yes, I am asking if you are certain about the host name. As the R library appears to be running Java under the hood, I also asked whether you have tried connecting directly via Java. – Tim Biegeleisen Dec 10 '17 at 13:25
  • I had also tried a different host name (with gmail in it) but didnt work either. As for Java I really just know R... – ML_Enthousiast Dec 10 '17 at 14:52
  • I don't know this API well enough to be of much use to you. I can only recommend that you take apart your call and try to see if each piece is working correctly. Checking that domain some how would be a good step in that direction. – Tim Biegeleisen Dec 10 '17 at 14:55
  • You can answer your own question below. – Tim Biegeleisen Dec 10 '17 at 23:05

1 Answers1

1

I finally managed to make it work ! You have to authorize the app on Google. This link really helped me: https://medium.com/airbnb-engineering/using-googlesheets-and-mailr-packages-in-r-to-automate-reporting-c09579e0377f

ML_Enthousiast
  • 1,147
  • 1
  • 15
  • 39