Advertisement
Guest User

Untitled

a guest
Aug 1st, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. package SendEmail;
  2.  
  3. import java.util.*;
  4. import javax.mail.*;
  5. import javax.mail.internet.*;
  6. import javax.mail.internet.MimeMessage;
  7. public class SendEmail {
  8.  
  9. public static void main(String args[]){
  10. try{
  11. String host ="smtp.gmail.com" ;
  12. String user = "Your Email";
  13. String pass = "Your Password";
  14. String to = "Reciever Email";
  15. String from = "Your Email";
  16. String subject = "TEST EMAIL";
  17. String messageText = "This email is a test";
  18. boolean sessionDebug = false;
  19.  
  20. Properties props = System.getProperties();
  21.  
  22. props.put("mail.smtp.starttls.enable", "true");
  23. props.put("mail.smtp.host", host);
  24. props.put("mail.smtp.port", "587");
  25. props.put("mail.smtp.auth", "true");
  26. props.put("mail.smtp.starttls.required", "true");
  27.  
  28. java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
  29. Session mailSession = Session.getDefaultInstance(props, null);
  30. mailSession.setDebug(sessionDebug);
  31. Message msg = new MimeMessage(mailSession);
  32. msg.setFrom(new InternetAddress(from));
  33. InternetAddress[] address = {new InternetAddress(to)};
  34. msg.setRecipients(Message.RecipientType.TO, address);
  35. msg.setSubject(subject); msg.setSentDate(new Date());
  36. msg.setText(messageText);
  37.  
  38. Transport transport=mailSession.getTransport("smtp");
  39. transport.connect(host, user, pass);
  40. transport.sendMessage(msg, msg.getAllRecipients());
  41. transport.close();
  42. System.out.println("message send successfully");
  43. }catch(Exception ex)
  44. {
  45. System.out.println(ex);
  46. }
  47.  
  48. }
  49. }
  50.  
  51. javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbsU
  52. 534-5.7.14 t3OAVI8JE19aKku2h4ZjEX_buFcH_KGTK-duOfH_YcQHPverRtgEyegDwBN4uelBea8Lyc
  53. 534-5.7.14 rxgCTVHxUciyb9STZ1Lgr19bd2SLJAyI55htJ1C_HFJo2NYu5DU-HNwQ6UbCShxgmslvXU
  54. 534-5.7.14 d_bckUCctyNWVNMf8my29et9jx8tliyClKsUW6zY_2WbLonmHG4aODJUoal7O-Qs0RKvTb
  55. 534-5.7.14 opqVsGO_QwUcMl9fQUlGc9SYf6BSU> Please log in via your web browser and
  56. 534-5.7.14 then try again.
  57. 534-5.7.14 Learn more at
  58. 534 5.7.14 https://support.google.com/mail/answer/78754 h16sm28086045wrc.89 - gsmtp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement