Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i have developed a small application for customer inquiries?

its like user can enter customer details to several text boxes like,

Customer name
Customer telephone number
Customer issue.

after user finished entering data. there is a submit button and once user click it.
the details will send to another person.
as an example : manager person.

i have used java mail api? for that.

it will build the program successfully

but on the same time it will give an exception error as well.

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbvG
534-5.7.14 5tY-sFXWUo7QgeGofeaJDvflnO7Pt-_gbScu4j3cTrL_lT6rDn3R7EXWz-CElFeN9XwzWc
534-5.7.14 qYMVg5da2ff4UGzc1EUBDnTyzHHCG-y-sZ-zMkflYTg7rXRmmNesZ8C-OoSYaGt642vj2z
534-5.7.14 njfbhASCvcai7lV7dTvDdH79szsHKW8rD1XGD11SYDp-oc4BIrp88HoqamghSPfEp1T8CH
534-5.7.14 Mx49SUYyhUDtpw5J6HlFT6eoF9588> 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 o71sm37079708pfj.68 - gsmtp

What I have tried:

private void enqSubActionPerformed(java.awt.event.ActionEvent evt) {

final String username = "hemastravelsit@gmail.com";
final String password = "Hemas@9000";

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");// this is the smtp server address
props.put("mail.smtp.port","587");//This is the port for the smtp server

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("hemastravelsit@gmail.com"));//from emailaddress
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("businesssupport.travels@hemas.com"));//to email address
message.setSubject("My first Email");//sets subject of email
message.setContent("<h:body style="background-color:white;font-family:verdana:color:#0066CC:" xmlns:h="#unknown">"
+"if you are getting this you wrote your first email!

"
+"</body>","text/html; charset=utf-8");//Sets the content body of the email
Transport.send(message);//sends the entire message object
System.out.println("was the email sent: Done");// verifies that the code fired
}
catch(MessagingException e){
throw new RuntimeException(e);// If the email address is bad or doesnt excist
}

}
Posted
Updated 20-Mar-16 22:33pm
Comments
Garth J Lancaster 21-Mar-16 3:48am    
did you follow the instructions in the exception ? ie logging in to your google account/following the link they supplied https://support.google.com/mail/answer/78754 o71sm37079708pfj.68 - gsmtp ??
Hemas Ilearn 21-Mar-16 4:15am    
that link is not working?
Garth J Lancaster 21-Mar-16 4:33am    
have a look at the last line of the exception you posted - its there
Hemas Ilearn 21-Mar-16 4:37am    
its fine.. i have enabled less security app option.
https://support.google.com/accounts/answer/6010255

1 solution

One thing to note is that, in most of the cases of Google SMTP server, is that it won't allow SMTP consumption directly, if your account doesn't allow. In many cases, I have seen that many developers have written a correct implementation of the protocol API, but still they cannot send the email. In that case, make sure that your account allows SMTP communication through your authentication. It is in your settings, check it.

Later, the problem is still the authentication to your account. For example, see the error message:

Quote:
javax.mail.AuthenticationFailedException...Please log in via your web browser and then try again.
This tells that you need to authenticate the system to use that account. Google does not allow your application to use this.

One of the following may be the reason:

1. Your account is a new one. Google fights against spam; or that is what they tell us. :laugh:
2. Make sure you can sign in to account from web browser, try your luck at: mail.google.com.
3. Make sure application is supported as per security standards; SSL, port and authentication etc.
4. Much more.

These are a few of the major things that you need to keep in mind. Your code is correct, the problem is with authentication. Either the username/password is incorrect, otherwise Google is preventing your app to communicate.

Also, the help URL is: Can’t sign in to my email app - Gmail Help[^], you are using the wrong one. :-)

For more, please read these:

JavaMail API &#8211; Sending email via Gmail SMTP example[^]
java - Solve error javax.mail.AuthenticationFailedException - Stack Overflow[^]
 
Share this answer
 
v2

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