Expand my Community achievements bar.

SOLVED

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

Avatar

Community Advisor

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 ?

1 Accepted Solution

Avatar

Correct answer by
Level 10

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

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

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