Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

ACS AEM Commons email Issue(Getting emailID in failureList

Avatar

Level 3

Hi everyone,

I am using acs aem commons email service for sending email.

I have written the code as per the documentation and given the acs commons user permission, but the sendEmail method returning the emailId ideally it should return the empty response as per the documention.

failureList = emailService.sendEmail(emailDetails.getTemplatePath(), emailDetails.getEmailParams(),
recipient);
I have checked and debug the code but I am unbale to find the issue.

Please let me know let me know if anyone has any idea on this.

PS: I follow https://adobe-consulting-services.github.io/acs-aem-commons/features/e-mail/email-api/index.html

url for reference.

 

@Jörg_Hoh @VeenaVikraman Can you please help.

 

Thanks,

 

18 Replies

Avatar

Level 3

Hi @Mohit_KBansal 

Yes, I have filled the day cq mail also. PFB SS:

kkhan_123_0-1669992530108.png

Please let me know If I missed something

 

Thanks

 

Avatar

Level 5

Hi @kkhan_123

Have you configured the SMTP configurations for your testing environment ?

Check the error logs if any error or network issues are thrown.

Avatar

Level 3

Hi @VeenaK ,

I have added the configuration and also I am not getting any error or exception.

Avatar

Community Advisor

HI @kkhan_123

Sometime if you are in your office network, this issue may arise due to network issues. Can you try in your home network or by connecting your mobile hotspot?

Hope this helps!

Thanks,

Kiran Vedantam.

Avatar

Level 3

Hi @Kiran_Vedantam
I already tried with different network, still not getting the email. Don’t know what I am missing here.

Thanks for the reply.

Avatar

Community Advisor

Hi @kkhan_123

Just try this once.

Using the Email API to send attachments (since v2.6.0/3.2.0)

The sendMail(..) method now supports the following signature:

public List<String> sendEmail(String templatePath, Map<String, String> emailParams, Map<String, DataSource> attachments, String... recipients)

public List<InternetAddress> sendEmail(String templatePath, Map<String, String> emailParams, Map<String, DataSource> attachments, InternetAddress... recipients)

Ref :https://adobe-consulting-services.github.io/acs-aem-commons/features/e-mail/email-api/index.html#usi...

Thanks

Avatar

Level 3

Hi @KNan ,

Tried the same still not getting the mail. Attaching the log information.

	try{
		ObjectMapper objMapper = new ObjectMapper();
		Map<String, DataSource> attachments = new HashMap<>();
		String attachmentContentsAsString = "This text should be in the attache txt file.";
		attachments.put("attachment1.txt", new ByteArrayDataSource(attachmentContentsAsString, "text/plain"));
		LOG.info("attachments value check-->{}", attachments);
		emailDetails.setTemplatePath(config.getShareFriendTemplate());
		LOG.info("emailParams -->{}", objMapper.convertValue(emailDetails, Map.class));
		Map<String, String> emailParams = objMapper.convertValue(emailDetails, Map.class);
		emailParams.remove("emailParams");
		LOG.info("emaildetails before-->{}", emailDetails);
		emailDetails.setEmailParams(emailParams);
		LOG.info("template path {}", emailDetails.getTemplatePath());
		LOG.info("params path {}", emailDetails.getEmailParams());
		LOG.info("recipient path {}", emailDetails.getRecipients());
		String[] recipient = {emailDetails.getRecipients(), "aaqibkhan.3may@gmail.com"};
		failureList = emailService.sendEmail(emailDetails.getTemplatePath(), emailDetails.getEmailParams(),attachments,
				recipient);
        if (failureList.isEmpty()) {
            LOG.info("Email sent successfully to {} recipients", failureList.size());
        } else {
            LOG.info("Email sent failed:{}",failureList);
        }
	}catch(Exception e){
		LOG.info("Exception value check:{}->", e);
	}

		return failureList.size();
	}

Please let me know if you need any other information.

Thanks.

Avatar

Community Advisor

If you want, you can try below solution for sending an email

https://aemlab.blogspot.com/2019/06/aem-custom-templated-email.html 



Arun Patidar

Avatar

Level 3

Hi @arunpatidar 

Tried the approach mentioned in the blog getting the email sent response but still not getting email.

kkhan_123_0-1670248490061.png

I also hit the servlet path here also I am getting sent email reponse.

kkhan_123_0-1670250995244.png

 

	@Override
	protected void doGet(final SlingHttpServletRequest req, final SlingHttpServletResponse resp)
			throws ServerException, IOException {
		try {
			resp.setContentType("text/html");
			PrintWriter pw = resp.getWriter();
			Node templateNode = req.getResourceResolver().getResource(EMAIL_TEMPLATE).adaptTo(Node.class);
			final Map<String, String> parameters = new HashMap<String, String>();
			parameters.put("title", "Demo Email");
			parameters.put("name", "AAQIB");
			parameters.put("id", "0001");
			parameters.put("host.prefix", "http://localhost");
			parameters.put("faqpath", "/content/AEM63App/faq.html");
			final MailTemplate mailTemplate = MailTemplate.create(EMAIL_TEMPLATE, templateNode.getSession());
			HtmlEmail email = mailTemplate.getEmail(StrLookup.mapLookup(parameters), HtmlEmail.class);
			email.setSubject("AEM - Demo Email for Templated email");
			email.addTo("aaqibkhan.3may@gmail.com");
			MessageGateway<HtmlEmail> messageGateway = messageGatewayService.getGateway(HtmlEmail.class);
			messageGateway.send(email);
			pw.write("email sent");
			pw.close();
		} catch (Exception e) {
			log.info("Exception check:{}->",e);
			resp.getWriter().write(e.getMessage());
			resp.getWriter().close();
		}
	}

kkhan_123_1-1670248631032.png

Could you please tell me where I am making mistake.

 

Thanks,

Avatar

Community Advisor

Hi,

The problem could be at email server/SMTP server side.

The the email queue or try using gmail/any other SMTP server for testing.Could be firewall also.



Arun Patidar

Avatar

Level 3

Thanks for the reply @arunpatidar 

I have added different SMTP host also still not getting email.

Avatar

Employee Advisor

@kkhan_123 

What error are you getting, can you add the screen shot. If no error and only empty response, that means emails have been triggered from ACS Tool on AEM. (screen shot attached)

 

krati_garg_0-1670238448430.png

 

If these email notifications have not been received, then there is an issue on the other end and not on AEM end. 

Avatar

Level 3

Hi @krati_garg ,

FailureList returning email, but ideally it should return the empty response.

PFB SS:

kkhan_123_0-1670245908778.png

Thanks for the reply.

Avatar

Level 3

Hi @krati_garg ,

After adding the different host getting the empty response which is correct one according to the document ,but still not getting the email.

 

Thanks,

Avatar

Employee Advisor

@kkhan_123 I believe, if the email is sent, then there must be an issue with Recipient's network - firewall 

Avatar

Level 3

Thanks for the reply @krati_garg

How to resolve the above issue Actually I have added different email I’d as recipient but still not getting the email(for example personal emails and company email)

Avatar

Employee

hi @kkhan_123  running in to same issue . did you find any resolution?