R facing SMTP error when automating email

121 Views Asked by At

I am trying to automate sending emails with attachment using R. But I am facing errors. How do I solve this?

Code:

library(mailR)
send.mail(from="<email>",
          to="<email>",
          subject="Test Email",
          body="Test Email",
          html=T,
          smtp=list(host.name = "smtp.office365.com",
                    port = 587,
                    user.name = "<email>",
                    passwd = "<pw>",
                    ssl = T),
          authenticate=T,
          attach.files='test.csv')

Error:

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:1469)
    at org.apache.commons.mail.Email.send(Email.java:1496)
    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:399)
...
EmailException (Java): Sending the email to the following server failed : smtp.office365.com:465[1] "Java-Object{org.apache.commons.mail.HtmlEmail@47af7f3d}"
0

There are 0 best solutions below