Using GMail SMTP in AEM 6.0

smtp

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.

  1. Disable the firewall on your laptop or PC.
  2. Use following screenshot for SMTP configuration.

smtp1

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

 

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s