Send an e-mail to R

Asked

Viewed 41 times

-1

I’m trying to e-mail through the R with the package mailR. I put the information that the package requests, but testing with different emails, I end up getting the same error.

My code:

library(mailR)

send.mail(from = "[email protected]",
          to = "[email protected]",
          subject = "E-mail teste",
          body = "Este e-mail foi enviado pelo R.",
          smtp = list(host.name = "SMTP.office365.com", port = 587, 
                      user.name = "[email protected]",            
                      passwd = "minhasenha", ssl = TRUE), 
          authenticate = TRUE,
          send = TRUE)

Error that is returning:

org.apache.commons.mail.EmailException: Sending the email to the following server failed : SMTP.office365.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.invokNULL
eMethod(RJavaTools.java:386)
Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: SMTP.office365.com, 465; timeout 60000;
  nested exception is:
    java.net.ConnectException: Connection timed out: connect
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2053)
    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.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
    at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:310)
    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.office365.com:465

1 answer

1


Dude, I also tried to do this last week with this package, and I couldn’t (a specific gmail problem is that it doesn’t let third-party apps send or receive emails. The other emails should also have a similar restriction). Usually these problems you are facing is due to security imposed by the mail server. Apart from this package, I tried another 5 and none worked in a "natural" way, that is, without needing to change email configuration.

The only one that worked was gmailr. I’d test that one. You can follow the steps of that link

  • 1

    Thank you! The tutorial worked perfectly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.