Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.Velo;
- /*
- https://www.youtube.com/watch?v=A7HAB5whD6I
- Gmail SMTP Host: smtp.gmail.com
- Gmail SMTP Port: 587
- Download Java Mail API : https://javaee.github.io/javamail/
- Enable signin from less secure apps in Gmail: https://myaccount.google.com/security
- */
- import javax.mail.Message;
- import javax.mail.MessagingException;
- import javax.mail.PasswordAuthentication;
- import javax.mail.Session;
- import javax.mail.Transport;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- import java.util.Properties;
- public class Main {
- public static void main(String[] args) {
- final String password="MyPasswordhere123545";
- Properties props = new Properties();
- props.put("mail.smtp.ssl.trust", "*");
- props.put("mail.smtp.auth", "true");
- props.put("mail.smtp.port", "587");
- props.put("mail.smtp.host", "smtp.gmail.com");
- props.put("mail.smtp.starttls.enable", "true");
- Session session = Session.getDefaultInstance(props,
- new javax.mail.Authenticator() {
- protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(user,password);
- }
- });
- try {
- MimeMessage message = new MimeMessage(session);
- message.setFrom(new InternetAddress(user));
- message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
- message.setSubject("Alert de Mot de passe");
- message.setText("Validation de mot de passe de votre compte , svp vérifier !!! ");
- Transport.send(message);
- System.out.println("email envoyer avec succès...");
- } catch (MessagingException e) {e.printStackTrace();}
- }
- }
Add Comment
Please, Sign In to add comment