Guest User

Untitled

a guest
Feb 26th, 2018
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. public void envoye(String adressMail, String ContenuMail, String subject) {
  2.  
  3. boolean debug = false;
  4.  
  5. //Set the host smtp address
  6. Properties props = new Properties();
  7. props.put("mail.smtp.starttls.enable", true);
  8. props.put("mail.smtp.host", "smtp.gmail.com");
  9. props.put("mail.smtp.user", "eshop.tunisiepidev@gmail.com");
  10. props.put("mail.smtp.password", "eshoppidev");
  11. props.put("mail.smtp.port", 587);
  12. props.put("mail.smtp.auth", true);
  13. props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
  14. Session session = Session.getDefaultInstance(props, null);
  15. session.setDebug(debug);
  16.  
  17. Message msg = new MimeMessage(session);
  18.  
  19. InternetAddress addressFrom;
  20. try {
  21. addressFrom = new InternetAddress("eshop.tunisiepidev@gmail.com");
  22.  
  23. InternetAddress addressTo = new InternetAddress(adressMail);
  24.  
  25. msg.setRecipient(Message.RecipientType.TO, addressTo);
  26. msg.setFrom(addressFrom);
  27.  
  28. msg.setSubject(subject);
  29. msg.setText(ContenuMail);
  30. Transport t = session.getTransport("smtp");
  31. t.connect("smtp.gmail.com", "eshop.tunisiepidev@gmail.com", "eshoppidev");
  32. t.sendMessage(msg, msg.getAllRecipients());
  33. t.close();
  34. } catch (MessagingException ex) {
  35. ex.printStackTrace();
  36. }
  37. }
  38.  
  39. Couldn't connect to host, port: smtp.gmail.com, 587; timeout -1;
Add Comment
Please, Sign In to add comment