April 10, 2020
Estimated Post Reading Time ~

How to configure Email Notification?

In order to send an email from CQ, the Day CQ Mail Service needs to be configured properly. 

Procedure: 1. Go to felix web console (http://<host-name>:<port>/system/console/configMgr)
2. Search for Day CQ Mail Service
3. Edit and configure as follows:

a. The SMTP server port must be 25 or higher.
b. The SMTP server host name must not be blank.
c. The "From" address must not be blank.

Screenshot:

Simple code to send an email there is different ways to send an email.

Method 1: Using SimpleEmail

SimpleEmail email = new SimpleEmail();
email.setHostName('smtp.gmail.com");
email.addTo("mail@gmail.com", "John Doe");
email.setFrom("yourmail@gmail.com", "Me");
email.setSubject("Test message");
email.setMsg("This is a simple test of commons-email");
email.send();

Method 2: Using HtmlEmail without using MessageGateway

HtmlEmail email = new HtmlEmail();
email.setHostName("smtp.gmail.com");
email.addTo("mail@domain.com", "John Doe");
email.setFrom("yourmail@domain.com", "Me");
email.setSubject("Test email with inline image");

// set the html message //
email.setHtmlMsg("<html>The apache logo - <img src=\"cid:"
+cid+"\"></html>");

// set the alternative message
email.setTextMsg("Your email client does not support HTML messages");
email.send();

Note: We can also read smtp details from the felix console configurations instead of passing smtp details directly.



By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.