Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in sending email through Gmail by using mailR

Tags:

r

gmail

I am trying to send an email from RStudio using mailR package and gmail. The following is my code...

library(mailR)
sender <- "[email protected]"
recipients <- c("[email protected]")
send.mail(from = sender,
          to = recipients,
          subject = "Test mail from Rstudio",
          body = "Test email body",
          smtp = list(host.name = "smtp.gmail.com", port = 465, 
                      user.name = "[email protected]",            
                      passwd = "******", ssl = TRUE),
          authenticate = TRUE,
          send = TRUE)

I get the following error message...

org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:465
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1410)
    at org.apache.commons.mail.Email.send(Email.java:1437)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at RJavaTools.invokeMethod(RJavaTools.java:386)
Caused by: javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbuu
534-5.7.14 XIuKGOx55rNHFSvDWkzr2B1augfG-Z1zGTYEQ9IZ-iD_aDivhY0aUWNjt0C4ckYrqyx0WS
534-5.7.14 Zbz-1z65Xz8C1irD5crNwDSpgL3qQGgo6V-PvkiA6h1on6Hnn-YjSeho0uBWcG59x1C4TH
534-5.7.14 F6ZM2i2TToB9tIjzoUv_3encd3EW0Aw04XBaTVkoWseyUOaTTvglnCIj23ZNrIncqXW0f5
534-5.7.14 gjMKNtrSAOBmJxrgnXGrRS2BC9y9Q> Please log in via your web browser and
534-5.7.14 then try again.
534-5.7.14  Learn more at
534 5.7.14  https://support.google.com/mail/answer/78754 t62sm25604268pfa.38 - gsmtp

    at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:892)
    at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:814)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:728)
    at javax.mail.Service.connect(Service.java:386)
    at javax.mail.Service.connect(Service.java:245)
    at javax.mail.Service.connect(Service.java:194)
    at javax.mail.Transport.send0(Transport.java:253)
    at javax.mail.Transport.send(Transport.java:124)
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1400)
    ... 6 more
Error: EmailException (Java): Sending the email to the following server failed : smtp.gmail.com:465

What exactly I am doing wrong here? The google link mentioned in the error message doesn't exist.

EDIT: Got an email from google saying 'Sign-in attempt prevented: someone tried to sign in from an app that doesn't meet modern security standards... '

Is there a way around this? The google email doesn't say anything about allowing me to send message from R.

like image 377
Gaurav Avatar asked May 20 '16 09:05

Gaurav


People also ask

How to fix the “Gmail authentication failed” error?

How to fix the “Gmail Authentication failed. Please check your username/password” Error. Also known as the “Server response: 534-5.7.14 Error” Step 1. Sign into https://workspace.google.com/ with your Google Workspace Administrator domain, username and password.

How do I fix Gmail not responding?

Open Gmail. In the top right, click Settings See all settings. Next to any features you have enabled, select Disable. At the bottom of the page, click Save Changes. If the problem still isn't fixed, check the Google Workspace Status Dashboard to check if there's a known issue happening on Gmail.

Why is my Gmail not sending emails?

If your Gmail is not sending emails, we will tell you how to fix it. After navigating the causes, let’s move on with fixes. Our internet connection could be the one stopping you from sending any emails. Internet connection is very important while sending emails. If you use Wi-Fi, check and troubleshoot your LAN connection.

How do I fix Gmail errors on my iPhone or iPad?

If you get an error when you're using Gmail, like "Temporary Error," or "Oops," use this page to help you fix the issue. If you received this error on your iPhone or iPad, try the following steps: Make sure you're connected to the web. Close the app, then reopen it.


2 Answers

i have read through this and other threads carefully. i have the correct Java downloaded (64 bit), path to java env is correct, no 2FA set up on gmail, the "less secure app" access is on, yet neither through SSL + port 465 nor through TLS + port 587 am i able to send the email, i get this similar error to what's described above and in other question threads, those seem to be solved by either the 2FA issue or the "less secure app" issue - this one seems different... would really appreciate some help on this, already spent a good couple hours on it and going no where.

org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:465
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1410)
    at org.apache.commons.mail.Email.send(Email.java:1437)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at RJavaTools.invokeMetNULL
hod(RJavaTools.java:386)
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
  nested exception is:
    javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2055)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697)
    at javax.mail.Service.connect(Service.java:386)
    at javax.mail.Service.connect(Service.java:245)
    at javax.mail.Service.connect(Service.java:194)
    at javax.mail.Transport.send0(Transport.java:253)
    at javax.mail.Transport.send(Transport.java:124)
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1400)
    ... 6 more
Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
    at sun.security.ssl.HandshakeContext.<init>(Unknown Source)
    at sun.security.ssl.ClientHandshakeContext.<init>(Unknown Source)
    at sun.security.ssl.TransportContext.kickstart(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:543)
    at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:348)
    at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:215)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2019)
    ... 13 more
Error: EmailException (Java): Sending the email to the following server failed : smtp.gmail.com:465
like image 132
Guy Manova Avatar answered Oct 09 '22 03:10

Guy Manova


Enable access to 'less secure apps' here:

http://www.google.com/settings/security/lesssecureapps

like image 20
shreyasgm Avatar answered Oct 09 '22 03:10

shreyasgm