Gaurav Gaurav - 1 month ago 9
R Question

Error in sending email through Gmail by using mailR

I am trying to send an email from RStudio using

package and gmail. The following is my code...

sender <- ""
recipients <- c("")
send.mail(from = sender,
to = recipients,
subject = "Test mail from Rstudio",
body = "Test email body",
smtp = list( = "", port = 465, = "",
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 :
at org.apache.commons.mail.Email.sendMimeMessage(
at org.apache.commons.mail.Email.send(
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(
Caused by: javax.mail.AuthenticationFailedException: 534-5.7.14 <
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 t62sm25604268pfa.38 - gsmtp

at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(
at com.sun.mail.smtp.SMTPTransport.authenticate(
at com.sun.mail.smtp.SMTPTransport.protocolConnect(
at javax.mail.Service.connect(
at javax.mail.Service.connect(
at javax.mail.Service.connect(
at javax.mail.Transport.send0(
at javax.mail.Transport.send(
at org.apache.commons.mail.Email.sendMimeMessage(
... 6 more
Error: EmailException (Java): Sending the email to the following server failed :

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.

Answer Source

Enable access to 'less secure apps' here: