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 44 45 46 47 48
| package aaa;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import bdd.connexion;
public class smtpTest {
public static void main (String[] args) throws Exception {
String smtpHost = "smtp.gmail.com";
String from = "xxxx@gmail.com";
String to = "xxxx@gmail.com";
String username = "xxxxxx";
String password = "zzzzzzzzz";
Properties props = new Properties();
props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props);
session.setDebug(true);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Hello");
message.setContent("Salam","text/html");*/
Transport tr = session.getTransport("smtp");
tr.connect(smtpHost, username, password);
message.saveChanges();
// tr.send(message);
/** Genere l'erreur. Avec l authentification, oblige d utiliser sendMessage meme pour une seule adresse... */
tr.sendMessage(message,message.getAllRecipients());
tr.close();
System.out.print("Done :D");
}
} |
Partager