title: I am getting errors while trying to send an email with JavaMail
body: <p>I can successfully access my email folder using Folder and Store however when I try to send an email, I get an error.</p>
  
  <p>Code I use to attempt to send an email:</p>
  
  <pre><code>private static final String host = "smtp.google.com";
  private static final String user = "fakeaddress@gmail.com";
  private static final String pass = "fakepassword";
  
  private static Properties props = null;
  private static Session session = null;
  
  public static void main(String[] args){
  
      props = new Properties();
      props.put("mail.smtp.host", host);
      props.put("mail.from", user);
  
      session = Session.getDefaultInstance(props, null);
  
  
      MimeMessage mime = new MimeMessage(session);
      mime.setFrom(new InternetAddress(user));
      mime.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
      mime.setSubject("Email from: " + user);
      mime.setText(msg);
      Transport.send(mime);
  }
  </code></pre>
  
  <p>The error message I get:</p>
  
  <pre><code>com.sun.mail.util.MailConnectException: Couldn't connect to host, port:smtp.google.com, 25; timeout -1;
    nested exception is:
          java.net.UnknownHostException: smtp.google.com
          at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1961)
          at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
          at javax.mail.Service.connect(Service.java:345)
          at javax.mail.Service.connect(Service.java:226)
          at javax.mail.Service.connect(Service.java:175)
          at javax.mail.Transport.send0(Transport.java:253)
          at javax.mail.Transport.send(Transport.java:124)
  
  
          at com.mangopearapples.pcc.addons.EmailAddon.sendMail(EmailAddon.java:147)
          at com.mangopearapples.pcc.addons.EmailAddon.main(EmailAddon.java:106)
  
  
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:491)
          at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
  Caused by: java.net.UnknownHostException: smtp.google.com
          at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
          at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
          at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
          at java.net.Socket.connect(Socket.java:585)
          at java.net.Socket.connect(Socket.java:534)
          at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:297)
          at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:229)
          at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1927)
          ... 13 more
  Error getting email: Messaging error - Couldn't connect to host, port: smtp.google.com, 25; timeout -1
  </code></pre>
  
  <p>The lines of my class which the error message references (EmailAddon.java:147) are:</p>
  
  <pre><code>Transport.send(mime);
  </code></pre>
  
  <p>As said before, I can successfully access the email using Folder methods such as Folder.getUnreadMessageCount() successfully so I know the host, email address and password are not a problem.</p>
  
  <p>Thanks.</p>