Guest User

Untitled

a guest
Apr 4th, 2018
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. import java.util.Properties;
  2. import javax.mail.*;
  3. import javax.mail.Message;
  4. import javax.mail.MessagingException;
  5. import javax.mail.Session;
  6. import javax.mail.Transport;
  7. import javax.mail.internet.InternetAddress;
  8. import javax.mail.internet.MimeMessage;
  9.  
  10. public class birthdaywishscheduler {
  11.  
  12. public static void main(String args[]){
  13. final String username = "gfcgcc987@gmail.com";
  14. final String password = "jhgvjhbjj";
  15.  
  16. final String to = mailid;
  17. final String subject = "Happy Birthday from our company";
  18. final String messg = "Have a wonderful birthday! Dear QWERTY It’s our pleasure to wish you the best day of the year";
  19.  
  20.  
  21. final String from = "gfcgcc987@gmail.com";
  22. final String pass = "jhgvjhbjj";
  23.  
  24. Properties props = new Properties();
  25. props.put("mail.smtp.auth", true);
  26. props.put("mail.smtp.starttls.enable", true);
  27. props.put("mail.smtp.host", "smtp.gmail.com");
  28. props.put("mail.smtp.port", "587");
  29.  
  30. Session session1 = Session.getInstance(props,
  31. new javax.mail.Authenticator() {
  32. protected PasswordAuthentication getPasswordAuthentication() {
  33. return new PasswordAuthentication(username, password);
  34. }
  35. });
  36.  
  37. try {
  38. Message message = new MimeMessage(session1);
  39. message.setFrom(new InternetAddress(from));
  40. message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
  41. message.setSubject(subject);
  42. message.setText(messg);
  43. // Send message
  44. Transport.send(message);
  45. System.out.print("Your mail sent successfully....");
  46. } catch (MessagingException mex) {
  47. mex.printStackTrace();
  48. //out.println(mex);
  49. System.out.print("Error: unable to send mail....");
  50. }
  51.  
  52. }
  53.  
  54. }
Add Comment
Please, Sign In to add comment