1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
   | <div style="margin-left:40px">   public void launch() {
 
     try {
      startTimeToConnect = System.currentTimeMillis();   
      Properties props = System.getProperties();
      props.put("mail.smtp.auth", "true");
 
       // Get a Session object
      Session mailSession = Session.getDefaultInstance(props, null);
 
      // construct the message
      Message msg = new MimeMessage(mailSession);
      msg.setFrom(new InternetAddress(from));
 
       msg.setRecipients(Message.RecipientType.TO,
                        InternetAddress.parse(to, false));
 
       msg.setSubject(subject);
 
       msg.setText("Sample Message");
 
       msg.setHeader("X-Mailer", mailer);
 
       //Pour avoir un accusé. Ne marche pas
       //msg.setHeader("Disposition-Notification-To",from);
       //msg.setHeader("Return-Receipt-To",from);
       //
 
      msg.setSentDate(new Date());
 
      Transport tr  = mailSession.getTransport("smtp");
      tr.connect(smtphost, username, password);
      msg.saveChanges(); // don't forget this
      tr.sendMessage(msg, msg.getAllRecipients());
      tr.close();
 
       System.out.println("\nMail was sent successfully.");
       System.out.println (System.currentTimeMillis() - startTimeToConnect);
     }
     catch (Exception e) {
          e.printStackTrace();
     }
  }</div> | 
Partager