If you are trying to use Gmail SMTP in AEM 6.0 or any Java based Mail Client and see above error logs.. authentication failed…not able to connect to smtp.gmail.com etc please make sure 2 things are done at your client machine where you are testing. i spend 4 to 5 hours to find the solution.
- Disable the firewall on your laptop or PC.
- Use following screenshot for SMTP configuration.
Sample code here.
List<InternetAddress> emailRecipients = new ArrayList<InternetAddress>();
try {
@Reference
private MessageGatewayService messageGatewayService;
@Reference
private MessageGateway<HtmlEmail> messageGateway;
HtmlEmail email = new HtmlEmail();
emailRecipients.add(new InternetAddress(userName));
email.setTo(emailRecipients);
email.setSubject(“XXX Password Reset”);
StringBuffer sb = new StringBuffer();
sb.append(“<b>XXX Password Reset</b> <BR> To: “+userName);
sb.append(content);
email.setHtmlMsg(sb.toString());
messageGateway = messageGatewayService.getGateway(HtmlEmail.class);
messageGateway.send(email);
} catch (Exception ex) {
ex.printStackTrace();
LOGGER.debug(” Exception caught in send email” + ex.getMessage());
return false;
}