title: Unable to send emails to web mail servers from local server using Java Mail
body: <p>I am trying to send emails from Java Mail API. Currently I have installed <code>Apache James</code> as a testing mail server of my own. I have few email account users in James, they are "red", "green" and "blue". </p>
  
  <p>Now, please have a look at the below code.</p>
  
  <pre><code>/*
   * To change this license header, choose License Headers in Project Properties.
   * To change this template file, choose Tools | Templates
   * and open the template in the editor.
   */
  
  /**
   *
   * @author Yohan
   */
  
  import java.util.*;  
  import javax.mail.*;  
  import javax.mail.internet.*;  
  import javax.activation.*;  
  
  public class Mail {
  
       public static void main(String [] args){  
        String host="localhost";  
    final String user="red@localhost";//change accordingly  
    final String password="red";//change accordingly  
  
    String to="abc@gmail.com";//change accordingly  
    //String to= "blue@localhost";
  
     //Get the session object  
     Properties props = new Properties();  
     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);  
        }  
      });  
  
     //Compose the message  
      try {  
       MimeMessage message = new MimeMessage(session);  
       message.setFrom(new InternetAddress(user));  
       message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));  
       message.setSubject("Test Mail From Localhost");  
       message.setText("Soetimes, it didnt work..");  
  
      //send the message  
       Transport.send(message);  
  
       System.out.println("message sent successfully...");  
  
       } catch (MessagingException e) {e.printStackTrace();}  
   }  
  
  
  }
  </code></pre>
  
  <p>There is a problem in this code. That is if I send the mail to a local email like blue@localhost, the mail will be sent. If I send it to a web based one like "Gmail", it do not go. However in both cases, I get the message `message sent successfully....</p>
  
  <p>what is happening here?</p>