I have an Email hosting account to my company from Gmail and am trying to send Emails from this account in java but am facing the following error:
javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbsF
534-5.7.14 i7ZvgRt2ia4HE_atVycPueORguLHg4yVG6hw_JGdAgbyUkBfJySVDR_XvkzLZzQp88F-UN
534-5.7.14 aoGU0uN-UBUR91zW7jsbzeq8Ojr6FEjFQcpsVKpv9GLaUPY3ee-pUk3Y6eNABFeA8DgDlu
534-5.7.14 fNDQwLg_R1I5-veyWJ8qE73R833F8PHWFuRanCjTkyPjQogqO-VrBG6omrZHsP3I-8Wphr
534-5.7.14 AjvaiqquhwnrUrmKjyk6RKaJnYaiA> 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 w77sm17182835wmw.10 - gsmtp
and here is the properties am using in my code:
final String username = "email@mycompnay.com";
final String password = "********";
final String host = "smtp.gmail.com";
final String port = "587";
// Creating Properties object
Properties props = new Properties();
// Defining properties
props.put("mail.smtp.host", host);
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.user", username);
props.put("mail.password", password);
props.put("mail.port", port);
// Authorized the Session object.
Session mailSession = Session.getInstance(props, new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
So to be clear, my email is (myemail@mycompany.com) and mycompany.com emails are hosted on Gmail. And if I replace my email with a Gmail Email like (email@gmail.com) it works properly, So what is the problem here and how to solve it.