Click here to Skip to main content
15,889,825 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
my code


Java
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);
		}
	}
}









error




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)
Posted
Updated 8-Dec-15 23:40pm
v2
Comments
Richard MacCutchan 9-Dec-15 6:35am    
The error messages are quite clear, go to google and check why it fails.
Member 12115149 9-Dec-15 6:44am    
i have problem so i am ask.i am not understand
Richard Deeming 9-Dec-15 10:15am    
Open the link from the error message, and go through the troubleshooting steps:
https://support.google.com/mail/answer/14257[^]

1 solution

Do NOT use Gmail for development! Get your own little local email server.

Gmail doesn't want you to access an email account every couple of minutes due to testing your code.
The ban you 15min. before they accept another attempt.

So please check hmail server, it's a simple little thingy which runs very nice.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900