Advertisement
Guest User

Untitled

a guest
Jul 12th, 2016
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. Exception in thread "main" java.lang.RuntimeException: javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more at
  2. 535 5.7.8 https://support.google.com/mail/answer/14257 p63sm2092184pfp.65 - gsmtp
  3.  
  4. at com.gabjava.SendMailTLS.main(SendMailTLS.java:48)
  5. Caused by: javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more at
  6. 535 5.7.8 https://support.google.com/mail/answer/14257 p63sm2092184pfp.65 - gsmtp
  7.  
  8. at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:648)
  9. at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:583)
  10. at javax.mail.Service.connect(Service.java:297)
  11. at javax.mail.Service.connect(Service.java:156)
  12. at javax.mail.Service.connect(Service.java:105)
  13. at javax.mail.Transport.send0(Transport.java:168)
  14. at javax.mail.Transport.send(Transport.java:98)
  15. at com.gabjava.SendMailTLS.main(SendMailTLS.java:43)
  16.  
  17. import java.util.Properties;
  18.  
  19. import javax.mail.Message;
  20. import javax.mail.MessagingException;`enter code here`
  21. import javax.mail.PasswordAuthentication;
  22. import javax.mail.Session;
  23. import javax.mail.Transport;
  24. import javax.mail.internet.InternetAddress;
  25. import javax.mail.internet.MimeMessage;
  26.  
  27. public class SendMailTLS {
  28.  
  29. public static void main(String[] args) {
  30.  
  31. final String username = "username";
  32. final String password = "userpassword";
  33.  
  34. Properties props = new Properties();
  35. props.put("mail.smtp.auth", "true");
  36. props.put("mail.smtp.starttls.enable", "true");
  37. props.put("mail.smtp.host", "smtp.gmail.com");
  38. props.put("mail.smtp.port", "587");
  39.  
  40. Session session = Session.getInstance(
  41. props,
  42. new javax.mail.Authenticator() {
  43. protected PasswordAuthentication getPasswordAuthentication() {
  44. return new PasswordAuthentication(username, password);
  45. }
  46. }
  47. );
  48.  
  49. try {
  50. Message message = new MimeMessage(session);
  51. message.setFrom(new InternetAddress("From-email"));
  52. message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("to-email"));
  53. message.setSubject("U Got this??");
  54. message.setText("Then u succeeded,nn Good Job! and keep it up!!");
  55.  
  56. Transport.send(message);
  57.  
  58. System.out.println("Done");
  59.  
  60. }
  61. catch (MessagingException e) {
  62. throw new RuntimeException(e);
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement