title: Sending email with Java
body: <p>Below is a simple test class I wrote to send email using Java. I am trying to send the message from my localhost. But I get the following error message: </p>
  
  <pre><code>javax.mail.MessagingException: Unknown SMTP host: http://localhost:8080/;
  nested exception is:
  java.net.UnknownHostException: http://localhost:8080/
  at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1280)
  </code></pre>
  
  <p>I change to host value to simply "localhost" but I get the same problem. Any ideas on a fix? Would a real server work?</p>
  
  <pre><code>import java.util.Properties;
  import javax.mail.*;
  import javax.mail.internet.InternetAddress;
  import javax.mail.internet.MimeMessage;    
  
  public class MyEmail {
  
  public static void main(String... args) {
      String to = "me@email.com";
      String from = "other@email.com";
      String host = "http://localhost:8080/";
  
      Properties properties = System.getProperties();
      properties.setProperty("mail.smtp.host",host);
      Session session = Session.getDefaultInstance(properties);
  
      try{
          MimeMessage message = new MimeMessage(session);
          message.setFrom(new InternetAddress(from));
          message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
          message.setSubject("This is a subject");
          message.setText("The text is what it is the text");
          Transport.send(message);
          System.out.println("Successful");
      }catch(MessagingException mx){
          mx.printStackTrace();
      }
  }
  }
  </code></pre>