Question

Sending mail from my droplet via javax.mail

Posted May 15, 2021 230 views
UbuntuEmailNetworkingFirewallJavaLinux Commands

Hi! I want to send a email from a DOCKER CONTAINER which runs a Java-Rest-API running on my Droplet.
I’m using javax.mail to send emails. It works on my local Windows machine.
But i get this error when running it on my ubuntu droplet:
[ERROR@EMAIL] - javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
nested exception is:
javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)

Starting and creating my docker container with these commands:

  • mvn package -Dquarkus.native.container-build=true -DskipTests
  • docker build -f src/main/docker/Dockerfile.jvm -t pservice .
  • docker run –name pservice -i –rm -p 8080:8080 -d pservice
  • docker logs pservice -f

do i need to do something like -p 25:25? or -p 465:465?

What could be the problem? I already asked the support to open up the SMTP Ports for me, they did it. But it still won’t work.

1 comment

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi there,

According to the error you are using port 465 so as long as this port is open it should be alright.

You could test if this is the case for your server by running the following telnet command:

telnet smtp.gmail.com 465

Also, I think that the problem is with the ciphers as you are getting an SSL error.

You could try removing TLSv1 and TLSv1.1 from the file $JAVA_HOME/conf/security and give it another try.

Let me know how it goes.
Regards,
Bobby

  • https://imgur.com/a/mOREeNW
    I do get this return when using

    telnet smtp.gmail.com 465
    

    Seems to work fine.

    Do you think it could be a problem with the Docker Container?

  • Changing this TLS thing didn’t do anything sadly.
    I hope I did it right:
    Just deleted TLSv1 and TLSv1.1 from this file:

    $JAVA_HOME/conf/security/java.security
    

    Exactly at this part:

    jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, RC4, DES, MD5withRSA, \
        DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \
        include jdk.disabled.namedCurves
    
  • Maybe this helps:

     nmap -p 22,25,465,587 <my-ip>
    

    Response:

    
    Host is up (0.000039s latency).
    
    PORT    STATE  SERVICE
    22/tcp  open   ssh
    25/tcp  closed smtp
    465/tcp closed smtps
    587/tcp closed submission
    
    Nmap done: 1 IP address (1 host up) scanned in 0.26 seconds
    
    
    • Hi there @philipp323,

      It is normal to see the ports as closed for incoming connections. You would see the port open for incoming connections only if there is a service actually listening on that port on your server itself. But as you are using Gmail, you don’t actually run an SMTP server on the Droplet itself so this is why the ports report as closed when you try to do an incoming connection.

      The important part is that you have the ports open for outbound connections as your Droplet is going to be connecting to the Gmail SMTP service externally on those ports.

      On another note, did you try restarting the Docker container after editing the security file?

      It could indeed be something to do with the container, does the app run Ok if you run it directly on the Droplet and not inside a container?

      Regards,
      Bobby

      • I got some problems.
        1.:
        I didn’t understand that i need to edit this java.security file inside my docker container. Makes sense.
        So i tried it right now, connected to my docker container with exec, but i can’t edit it because nothing like nano is installed and i can’t use apt-get.

        bash: apt-get: command not found
        

        Could u explain me how to edit this file? I think the docker container, made by the quarkus-dockerfile is really slimmed down.

        2.:
        Yesterday I tried starting this maven program on my machine. It started. But It’s a Quarkus-REST-Application. So they are made to be dockered. So somehow it wasn’t accessible from outside, running on localhost. Sending EMAILS did not work. But I think it was not a problem concerning the ports.

      • Okay! Sending a email from outside the docker container works fine.