Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void envoye(String adressMail, String ContenuMail, String subject) {
- boolean debug = false;
- //Set the host smtp address
- Properties props = new Properties();
- props.put("mail.smtp.starttls.enable", true);
- props.put("mail.smtp.host", "smtp.gmail.com");
- props.put("mail.smtp.user", "eshop.tunisiepidev@gmail.com");
- props.put("mail.smtp.password", "eshoppidev");
- props.put("mail.smtp.port", 587);
- props.put("mail.smtp.auth", true);
- props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
- Session session = Session.getDefaultInstance(props, null);
- session.setDebug(debug);
- Message msg = new MimeMessage(session);
- InternetAddress addressFrom;
- try {
- addressFrom = new InternetAddress("eshop.tunisiepidev@gmail.com");
- InternetAddress addressTo = new InternetAddress(adressMail);
- msg.setRecipient(Message.RecipientType.TO, addressTo);
- msg.setFrom(addressFrom);
- msg.setSubject(subject);
- msg.setText(ContenuMail);
- Transport t = session.getTransport("smtp");
- t.connect("smtp.gmail.com", "eshop.tunisiepidev@gmail.com", "eshoppidev");
- t.sendMessage(msg, msg.getAllRecipients());
- t.close();
- } catch (MessagingException ex) {
- ex.printStackTrace();
- }
- }
- Couldn't connect to host, port: smtp.gmail.com, 587; timeout -1;
Add Comment
Please, Sign In to add comment