'mailR Error - Sending email to the following server failed: smtp.gmail.com:587 - ShinyProxy / Docker / Ubuntu

I am currently trying to publish my Shiny app via ShinyProxy and Docker.

Unfortunately, my app does not work after publishing - on the PC itself it works without any problems.

One of my problems concerns the package "mailR". I get the following error message when I try to send an email (excerpt, you can find the whole log below):

Warning: Error in : EmailException (Java): Sending the email to the following server failed : smtp.gmail.com:587

I have already tried to use the SSL port (465) instead of the TLS port - unfortunately without success.

I have to admit that I don't really understand SSL and TLS - so it's probably because I don't have any of the certificates "installed" (?). As I said before, the programme runs on my PC without any problems.

Here is some background info: My server runs on Ubuntu. I use Docker in combination with ShinyProxy. I use the package "mailR" and Java version 8. You can find my code at the end of the post.

If you need more info, feel free to tell me what exactly :)

Thank you very much and best regards


Complete error message

org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:587
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(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at RJavaTools.invokeMethod(RJavaTools.java:386)
Caused by: javax.mail.MessagingException: Could not convert socket to TLS;
  nested exception is:
javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1999)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:709)
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>(HandshakeContext.java:171)
at sun.security.ssl.ClientHandshakeContext.<init>(ClientHandshakeContext.java:98)
at sun.security.ssl.TransportContext.kickstart(TransportContext.java:220)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:428)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:543)
at com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:480)
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1994)
... 13 more
Warning: Error in : EmailException (Java): Sending the email to the following server failed : smtp.gmail.com:587
  1: shiny::runApp

Code extract which sends the e-mail

send.mail(from="[email protected]",
          to="[email protected]",
          subject="Test Email",
          body="PFA the desired document",
          html=T,
          smtp=list(host.name = "smtp.gmail.com",
                    port = 465, #or 587
                    user.name = "[email protected]",
                    passwd = "XPassword",
                    ssl = T), #or tls = T
          authenticate=T,
          attach.files=Pn)


Solution 1:[1]

personally, I could fix this error by upgrading both mailR and rJava to their latest versions.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gaut