title: sending mail using external smtp from container
body: <p>I prepared an app that can send mail through <code>smtp.gmail.com</code> and it works well but, when I run it using docker, I get an error - as it can't connect to <code>smtp.gmail.com</code>. The function sending mails is:</p>
  
  <pre><code>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("mail.smtp.host", "smtp.gmail.com");
     props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
     props.put("mail.smtp.port", "465");
     try{
          Authenticator auth = new SMTPAuthenticator();
          Session mailSession = Session.getDefaultInstance(props, auth);
          mailSession.setDebug(true);
          Transport transport = mailSession.getTransport();
  
          MimeMessage message = new MimeMessage(mailSession);
          message.setContent(body, "text/plain");
          message.addRecipient(Message.RecipientType.TO,
          new InternetAddress("mailRecipient"));
  
          transport.connect();
          transport.sendMessage(message,
          message.getRecipients(Message.RecipientType.TO));
          transport.close();  
      }
      catch(Exception e){
          System.out.println(e);
      }
  }
  </code></pre>
  
  <p>This is the error:</p>
  
  <blockquote>
    <p>myapp_thirdInst    | DEBUG SMTP: trying to connect to host
    "smtp.gmail.com", port 465, isSSL false</p>
    
    <p>myapp_thirdInst    | javax.mail.MessagingException: Unknown SMTP host:
    smtp.gmail.com;</p>
    
    <p>myapp_thirdInst    |   nested exception is:</p>
    
    <p>myapp_thirdInst    |  java.net.UnknownHostException: smtp.gmail.com</p>
    
    <p>myapp_thirdInst    | error sending mail</p>
  </blockquote>
  
  <p>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?</p>