sending mail using external smtp from container

I prepared an app that can send mail through and it works well but, when I run it using docker, I get an error – as it can’t connect to The function sending mails is:

public void sendEmal(String body, String mailRecipient){
   Properties props = new Properties();
   props.put("mail.transport.protocol", "smtp");
   props.put("mail.smtp.auth", "true");
   props.put("", "");
   props.put("mail.smtp.socketFactory.class", "");
   props.put("mail.smtp.port", "465");
        Authenticator auth = new SMTPAuthenticator();
        Session mailSession = Session.getDefaultInstance(props, auth);
        Transport transport = mailSession.getTransport();

        MimeMessage message = new MimeMessage(mailSession);
        message.setContent(body, "text/plain");
        new InternetAddress("mailRecipient"));

    catch(Exception e){

This is the error:

  • How can I solve the deployment/updating of dockerized app on my VPS?
  • polkit-gnome-authentication-agent-1 fail to start in docker without privileged flag
  • How many WordPress instances can i run on Google Compute engine in a single google cloud platform project.
  • Manage docker container security patchs
  • Running Nodejs Application in Amazon EC2 to serve my static content in nodejs using nginx as a reverse proxy
  • is it possible to speed up writes inside a docker container?
  • myapp_thirdInst | DEBUG SMTP: trying to connect to host
    “”, port 465, isSSL false

    myapp_thirdInst | javax.mail.MessagingException: Unknown SMTP host:;

    myapp_thirdInst | nested exception is:

    myapp_thirdInst |

    myapp_thirdInst | error sending mail

    It’s the first time I’m playing with docker and after some tries, it continues to fail. I’m kind of lost – could anyone give me a hint to solve this issue?

  • Cant get AngularJS site running in Docker Container
  • How to handle specific hostname like -h option in Dockerfile
  • How to make docker containers host-agnostic
  • How to prevent binding to docker0 bridge in overlay mode
  • Docker image from existing Rails/Unicorn/MySQL app
  • Accessing gitlab inside docker container from local machine
  • One Solution collect form web for “sending mail using external smtp from container”

    The first thing you need to do is get DNS working! Test the container DNS first with a shell, get that working and then your SMTP code may work.

    Perhaps you can update your question with information about your DNS configuration

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.