Advertisement
Guest User

Untitled

a guest
Apr 6th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package utils;
  7.  
  8. import java.util.Properties;
  9. import javax.mail.Message;
  10. import javax.mail.MessagingException;
  11. import javax.mail.PasswordAuthentication;
  12. import javax.mail.Session;
  13. import javax.mail.Transport;
  14. import javax.mail.internet.InternetAddress;
  15. import javax.mail.internet.MimeMessage;
  16.  
  17. /**
  18. *
  19. * @author khlifi
  20. */
  21. public class Mailer {
  22. final String username = "govoyage.wemtek@gmail.com";
  23. final String password = "Jredpalais007";
  24.  
  25. Properties props = new Properties();
  26.  
  27. public void SendMailGmail(String mailTo,String newpassword){
  28.  
  29.  
  30. props.put("mail.smtp.starttls.enable", "true");
  31. props.put("mail.smtp.auth", "true");
  32. props.put("mail.smtp.host", "smtp.gmail.com");
  33. props.put("mail.smtp.port", "587");
  34.  
  35. Session session = Session.getInstance(props,
  36. new javax.mail.Authenticator() {
  37. protected PasswordAuthentication getPasswordAuthentication() {
  38. return new PasswordAuthentication(username, password);
  39. }
  40. });
  41.  
  42. try {
  43.  
  44. Message message = new MimeMessage(session);
  45. message.setFrom(new InternetAddress("govoyage.wemtek@gmail.com"));
  46. message.setRecipients(Message.RecipientType.TO,
  47. InternetAddress.parse(mailTo));
  48. message.setSubject("Réinitialisation de votre mot de passe");
  49. message.setText("Votre nouveau mot de passe"
  50. + "\n\n"
  51. + newpassword);
  52.  
  53. Transport.send(message);
  54.  
  55. System.out.println("Done");
  56.  
  57. } catch (MessagingException e) {
  58. throw new RuntimeException(e);
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement