Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //JavaMailSender.java
- package com.Velo.EmailService;
- import javax.mail.*;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- import java.util.Properties;
- public class JavaMailSender {
- public static void main(String[] args) {
- String host="→myemailaddress@gmail.com←"; //← my email address
- final String user="→myemailaddress@gmail.com←";//← my email address
- final String password="→mypassword←";//change accordingly //← my email password
- String to="→Destination-emailaddress@gmail.com←";//→ the EMAIL i want to send TO →
- // session object
- 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);
- }
- });
- //My message :
- try {
- MimeMessage message = new MimeMessage(session);
- message.setFrom(new InternetAddress(user));
- message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
- message.setSubject(" NOTIFICATION APPOINTEMENTT !!! ");
- //Text in emial :
- //message.setText(" → Text message for Your Appointement ← ");
- //send the message
- Transport.send(message);
- System.out.println("message sent successfully via mail ... !!! ");
- } catch (MessagingException e) {e.printStackTrace();}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement