Hi arnab26
To send email from AEM to limited set of users, write an OSGi bundle that uses Java Mail API and you can send email. Now having said that - there may be libs that you need to deploy in bundle fragments to get an OSGi bundle using Java mail API working.
Please have a look at the following link doing above stated Link: -https://helpx.adobe.com/experience-manager/using/creating-custom-aem-workflow-steps.html
OR
OSGI bundle and can call it using Sling servlet or as a Service. Please have a look at the code below:-
String to = "sonoojaiswal1988@gmail.com";//change accordingly
String from = "sonoojaiswal1987@gmail.com";change accordingly
String host = "localhost";//or IP address
//Get the session object
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
Session session = Session.getDefaultInstance(properties);
//compose the message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("Ping");
message.setText("Hello, this is example of sending email ");
// Send message
Transport.send(message);
System.out.println("message sent successfully....");
You may use this code in doPost/doGet methods of OSGi when using it as Sling Servlet else you can use in some method of OSGI class and can invoke from JSP when using it as OSGI service.
I hope this will help you.
Thanks and Regards
Kautuk Sahni
Kautuk Sahni