How to send email using OSGi service by reading target url and email template path from servlet? | Community
Skip to main content
Suraj_Kamdi
Community Advisor
Community Advisor
November 13, 2018
Solved

How to send email using OSGi service by reading target url and email template path from servlet?

  • November 13, 2018
  • 2 replies
  • 2018 views

I have to create custom mail service using default mail service for sending different emails. I have to read the two parameters from sling servlet i.e. targetUrl and templatePath which will be used in custom mail service for appending each outgoing email. anyone has idea ?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

I am not sure what the issue is here. Read the two values from the servlet. Then use the MessageGateway service to send an email:

//Declare a MessageGateway service

        MessageGateway<Email> messageGateway;

             

        //Set up the Email message

        Email email = new SimpleEmail();

             

        //Set the mail values

        String emailToRecipients = "scottm@adobe.com";

        String emailCcRecipients = "ratna1.kumar@gmail.com";

         

        email.addTo(emailToRecipients);

        email.addCc(emailCcRecipients);

        email.setSubject("AEM Custom Step");

        email.setFrom("scottm@adobe.com");

        email.setMsg("This message is to inform you that the AEM content has been deleted");

         

        //Inject a MessageGateway Service and send the message

        messageGateway = messageGatewayService.getGateway(Email.class);

     

        // Check the logs to see that messageGateway is not null

        messageGateway.send((Email) email);

2 replies

Adobe Employee
November 13, 2018
smacdonald2008
smacdonald2008Accepted solution
Level 10
November 13, 2018

I am not sure what the issue is here. Read the two values from the servlet. Then use the MessageGateway service to send an email:

//Declare a MessageGateway service

        MessageGateway<Email> messageGateway;

             

        //Set up the Email message

        Email email = new SimpleEmail();

             

        //Set the mail values

        String emailToRecipients = "scottm@adobe.com";

        String emailCcRecipients = "ratna1.kumar@gmail.com";

         

        email.addTo(emailToRecipients);

        email.addCc(emailCcRecipients);

        email.setSubject("AEM Custom Step");

        email.setFrom("scottm@adobe.com");

        email.setMsg("This message is to inform you that the AEM content has been deleted");

         

        //Inject a MessageGateway Service and send the message

        messageGateway = messageGatewayService.getGateway(Email.class);

     

        // Check the logs to see that messageGateway is not null

        messageGateway.send((Email) email);