iifast

Untitled

Feb 12th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.05 KB | None | 0 0
  1. package com.Velo;
  2.  
  3. /*
  4. https://www.youtube.com/watch?v=A7HAB5whD6I
  5. Gmail SMTP Host: smtp.gmail.com
  6. Gmail SMTP Port: 587
  7. Download Java Mail API : https://javaee.github.io/javamail/  
  8. Enable signin from less secure apps in Gmail: https://myaccount.google.com/security
  9. */
  10.  
  11. import javax.mail.Message;
  12. import javax.mail.MessagingException;
  13. import javax.mail.PasswordAuthentication;
  14. import javax.mail.Session;
  15. import javax.mail.Transport;
  16. import javax.mail.internet.InternetAddress;
  17. import javax.mail.internet.MimeMessage;
  18. import java.util.Properties;
  19.  
  20. public class Main {
  21.  
  22.     public static void main(String[] args) {
  23.         String host="[email protected]";  
  24.         final String user="[email protected]";
  25.         final String password="MyPasswordhere123545";
  26.  
  27.         String to="[email protected]";
  28.  
  29.         Properties props = new Properties();
  30.         props.put("mail.smtp.ssl.trust", "*");
  31.  
  32.         props.put("mail.smtp.auth", "true");
  33.         props.put("mail.smtp.port", "587");
  34.         props.put("mail.smtp.host", "smtp.gmail.com");
  35.         props.put("mail.smtp.starttls.enable", "true");
  36.  
  37.         Session session = Session.getDefaultInstance(props,
  38.                 new javax.mail.Authenticator() {
  39.                     protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
  40.                         return new PasswordAuthentication(user,password);
  41.                     }
  42.                 });
  43.  
  44.      
  45.         try {
  46.             MimeMessage message = new MimeMessage(session);
  47.             message.setFrom(new InternetAddress(user));
  48.             message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
  49.             message.setSubject("Alert de Mot de passe");
  50.             message.setText("Validation de mot de passe de votre compte , svp vérifier !!! ");
  51.  
  52.        
  53.             Transport.send(message);
  54.  
  55.             System.out.println("email envoyer avec succès...");
  56.  
  57.         } catch (MessagingException e) {e.printStackTrace();}
  58.  
  59.     }
  60.     }
Add Comment
Please, Sign In to add comment