title: Java email program not sending emails
body: <p>I am working on a final project for one of my classes and this program is meant to send emails to address in the code. I know how most of the code works, just having trouble understanding the password authentication and how to connect to SMTP servers and using specific ports. The problem with the code is it's not sending the email when run, and not giving any error messages. Any help would be much appreciated. Here's the code. </p>
  
  <pre><code>    package application;
  
  import java.util.Properties;
  
  import javax.mail.Message;
  import javax.mail.MessagingException;
  import javax.mail.PasswordAuthentication;
  import javax.mail.Session;
  import javax.mail.Transport;
  import javax.mail.internet.InternetAddress;
  import javax.mail.internet.MimeMessage; 
  
  
  public class SendEmail {  
   public static void main (String [] args) {  
  
    String host="smtp.gmail.com";  
    final String user="myemail@gmail.com";
    final String password="password";
  
    String to="targetemail.com";
  
      //imported code
     Properties props = new Properties(); 
     props.put("mail.smtp.socketfactory.port",  "465");
     props.put("mail.smtp.port",  "465");
     props.put("mail.smtp.host",host);  
     props.put("mail.smtp.auth", "true");  
  
     Session session = Session.getDefaultInstance(props,  
      new javax.mail.Authenticator() {  
        protected PasswordAuthentication getPasswordAuthentication() {  
      return new PasswordAuthentication(user,password);  
        }  
      });  
  
   //imported code
          try {  
           MimeMessage message = new MimeMessage(session);  
           message.setFrom(new InternetAddress(user));  
           message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));  
           message.setSubject("Dwight from the future");  
           message.setText("At 8:00, someone poisons the coffee. Do NOT drink 
      it.");  
  
  
           Transport.send(message);  
  
           System.out.println("message sent!");  
  
           } 
          catch (MessagingException mex) 
          {
              System.out.println("Error: unable to send message....");
              mex.printStackTrace();
          }
       }  
     }  
  </code></pre>