import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class SendMailTLS { public static void main(String[] args) { final String username = "xxxxxx@gmail.com";//email id 1st final String password = "xxxxxxx"; //passwd Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("xxxxxxx@gmail.com")); ///email id message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("xxxxxxxx.com"));.//emailid message.setSubject("Testing Subject"); message.setText("Dear Mail Crawler," + "\n\n No spam to my email, please!"); Transport.send(message); System.out.println("Done"); } catch (MessagingException e) { throw new RuntimeException(e); } } }
Exception in thread "main" java.lang.RuntimeException: javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbvQM 534-5.7.14 kXHo4EvbKv_cmLZe8gJv18TKZblj07jc8Hm5Ox3uOVNKA0UwgZ3Q6wx2giu9mbtQFQCQ1I 534-5.7.14 oZrTJ145h7AmtFJnX7X1wLXtiX24Vfq6VsthKkCKtI87ajeuhxIaNyLfsHUVB3MdLi34i5 534-5.7.14 k_lzD0GN7Re_lUFBOssZ1Vv-mEQUQXOlRwhFLXp6ANiONmfayoNFB3a5FeW34Uy3THXq6P 534-5.7.14 isWuZaGIdJae2MJCdTwUQxrZXXws> Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 73sm10491911pfh.14 - gsmtp at SendEmail.SendMailTLS.main(SendMailTLS.java:48) Caused by: javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbvQM 534-5.7.14 kXHo4EvbKv_cmLZe8gJv18TKZblj07jc8Hm5Ox3uOVNKA0UwgZ3Q6wx2giu9mbtQFQCQ1I 534-5.7.14 oZrTJ145h7AmtFJnX7X1wLXtiX24Vfq6VsthKkCKtI87ajeuhxIaNyLfsHUVB3MdLi34i5 534-5.7.14 k_lzD0GN7Re_lUFBOssZ1Vv-mEQUQXOlRwhFLXp6ANiONmfayoNFB3a5FeW34Uy3THXq6P 534-5.7.14 isWuZaGIdJae2MJCdTwUQxrZXXws> Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 73sm10491911pfh.14 - gsmtp at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:809) at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:752) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:669) at javax.mail.Service.connect(Service.java:317) at javax.mail.Service.connect(Service.java:176) at javax.mail.Service.connect(Service.java:125) at javax.mail.Transport.send0(Transport.java:194) at javax.mail.Transport.send(Transport.java:124) at SendEmail.SendMailTLS.main(SendMailTLS.java:43)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)