Advertisement
Guest User

java mailing

a guest
Apr 5th, 2020
1,849
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.23 KB | None | 0 0
  1. youtube link : https://youtu.be/A7HAB5whD6I
  2.  
  3. Image : https://imgur.com/1G4PV6b
  4.  
  5.  
  6. package com.Velo.EmailService;
  7.  
  8. import javax.mail.*;
  9. import javax.mail.internet.InternetAddress;
  10. import javax.mail.internet.MimeMessage;
  11. import java.util.Properties;
  12.  
  13. public class JavaMailSender {
  14.  
  15.     public static void main(String[] args) {
  16.         String host="→myemailaddress@gmail.com←";  //← my email address
  17.         final String user="→myemailaddress@gmail.com←";//← my email address
  18.         final String password="→mypassword←";//change accordingly   //← my email password
  19.  
  20.         String to="→Destination-emailaddress@gmail.com←";//→ the EMAIL i want to send TO →
  21.  
  22.         // session object
  23.         Properties props = new Properties();
  24.         props.put("mail.smtp.ssl.trust", "*");
  25.         props.put("mail.smtp.auth", "true");
  26.         props.put("mail.smtp.port", "587");
  27.         props.put("mail.smtp.host", "smtp.gmail.com");
  28.         props.put("mail.smtp.starttls.enable", "true");
  29.  
  30.         Session session = Session.getDefaultInstance(props,
  31.                 new javax.mail.Authenticator() {
  32.                     protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
  33.                         return new PasswordAuthentication(user,password);
  34.                     }
  35.                 });
  36.  
  37.         //My message :
  38.         try {
  39.             MimeMessage message = new MimeMessage(session);
  40.             message.setFrom(new InternetAddress(user));
  41.             message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
  42.             message.setSubject(" NOTIFICATION APPOINTEMENTT !!! ");
  43.             //Text in emial :
  44.             //message.setText("  → Text message for Your Appointement ← ");
  45.             //Html code in email :
  46.             message.setContent(
  47.                     "<h1 style =\"color:red\" >DON'T MISS YOUR APPOINTEMENT !! </h1> <br/> <img width=\"50%\" height=\"50%\" src=https://i.imgur.com/iYcBkOf.png>",
  48.                     "text/html");
  49.  
  50.             //send the message
  51.             Transport.send(message);
  52.  
  53.             System.out.println("message sent successfully via mail ... !!! ");
  54.  
  55.         } catch (MessagingException e) {e.printStackTrace();}
  56.  
  57.     }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement