import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class Main {
 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  String host = "smtp.gmail.com";
  String username = "mail emetteur";
  String password = "password";
  String port = "465";
  String to = "mail destination"; // ou bien la liste des adresses de destination séparé par des virgules
  String subject = "Test d'envoi automatique par Java";
  String content = "Test d'envoi automatique de mail par Java en utilisant l'adresse: "+username;
  InternetAddress fromAddress =null ;
  InternetAddress[] addresses = null;
  try {
   addresses = InternetAddress.parse(to, true);
   fromAddress= new InternetAddress(username);
  } catch (AddressException e1) {
   // TODO Auto-generated catch block
   e1.printStackTrace();
  }
  
  Properties props = new Properties();
  props.put("mail.smtp.host", host);
  props.put("mail.smtp.user", username);
  props.put("mail.smtp.port", port);
  props.put("mail.smtp.starttls.enable","true");
  props.put("mail.smtp.auth", "true");
  props.put("mail.smtp.debug", "true");
  props.put("mail.smtp.socketFactory.port", port);
  props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
  props.put("mail.smtp.socketFactory.fallback", "false");
  System.out.println("creating session");
  Session session = Session.getDefaultInstance(props, null);
  System.out.println("creating message");
  MimeMessage message = new MimeMessage(session);
  try {
   message.setText(content);
   message.setSubject(subject);
   message.setFrom(fromAddress);
   message.setRecipients(Message.RecipientType.TO,addresses);
   message.setHeader("Disposition-Notification-To",fromAddress.getAddress());
   System.out.println("creating transport");
   Transport transport = session.getTransport("smtp");
   System.out.println("connecting to "+host+" with username = "+username);
   transport.connect(host, username, password);
   System.out.println("sending message");
   transport.sendMessage(message, message.getAllRecipients());
   transport.close();
   System.out.println("transport closed");
  } catch (MessagingException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  
 }
}