0

I am trying to use the mailR library in R to send mail. This is my code:

install.packages("sendmailR")
library(sendmailR)
sender <- "myemailid@umd.edu"
recipients <- "myemailid@gmail.com"
send.mail(from = sender,
      to = recipients,
      subject = "Subject of the email",
      body = "Body of the email",
      smtp = list(host.name = "exch.mail.umd.edu", port = 465,
                  user.name = "myemailid@umd.edu",            
                  passwd = "mypassword", ssl = TRUE),
      authenticate = TRUE,
      send = TRUE)

This code is giving me the following error:

org.apache.commons.mail.EmailException: Sending the email to the following server failed : exch.mail.umd.edu: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.MessagingException: Could not connect to SMTP host: exch.mail.umd.edu, port: 465;
nested exception is:
java.net.SocketException: Connection reset
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: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.security.ssl.InputRecord.readFully(Unknown Source)
at sun.security.ssl.InputRecord.read(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(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)

I am not able to get the reason behind this error even though the host name, sender and recipient address are all correct. I am using Windows 10 and R 3.2.2.

Hack-R
  • 22,422
  • 14
  • 75
  • 131
viralshah009
  • 81
  • 1
  • 2
  • 10

1 Answers1

0

Blocked sign-in attempt for security reasons

Google will continue to block sign-in attempts from the app you're using. To continue using this app, you can allow access to less secure apps, but your account may be more vulnerable

To allow access go to google account and turn on less secure app

Mehul Katara
  • 907
  • 11
  • 32