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 49 50 51 52 53
|
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "smtp.gmail.com");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.quitwait", "false");
//
Session session = Session.getDefaultInstance(props,new javax.mail.Authenticator()
{
protected Authentication getAuthentication()
{
//ton nom utilisateur et mot de passe
return new Authentication("logingmaiml","passwordgmail"); }
});
MimeMessage msg1 = new MimeMessage(session);
msg1.setSender(new InternetAddress("comtegmail@gmail.fr"));
msg1.setRecipients(Message.RecipientType.TO,"toto@yahoo.fr");
msg1.setSubject("JavaMail hello world example");
msg1.setSentDate(new Date());
msg1.setText("Hello, world!\n");
Transport.send(msg1); |
Partager