ACS AEM Commons email Issue(Getting emailID in failureList | Community
Skip to main content
Level 3
December 2, 2022

ACS AEM Commons email Issue(Getting emailID in failureList

  • December 2, 2022
  • 6 replies
  • 4716 views

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.

 

@joerghoh @veenavikraman Can you please help.

 

Thanks,

 

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

6 replies

Mohit_KBansal
Adobe Employee
Adobe Employee
December 2, 2022
kkhan_123Author
Level 3
December 2, 2022

Hi @mohit_kbansal 

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

Please let me know If I missed something

 

Thanks

 

Level 4
December 2, 2022

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.

kkhan_123Author
Level 3
December 2, 2022

Hi @veenak ,

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

Kiran_Vedantam
Community Advisor
Community Advisor
December 2, 2022

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.

kkhan_123Author
Level 3
December 2, 2022

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.

Community Advisor
December 3, 2022

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#using-the-email-api-to-send-attachments-since-v260320

Thanks

kkhan_123Author
Level 3
December 5, 2022

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.

arunpatidar
Community Advisor
Community Advisor
December 5, 2022

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
kkhan_123Author
Level 3
December 5, 2022

Hi @arunpatidar 

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

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

 

	@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();
		}
	}

Could you please tell me where I am making mistake.

 

Thanks,

arunpatidar
Community Advisor
Community Advisor
December 6, 2022

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
krati_garg
Adobe Employee
Adobe Employee
December 5, 2022

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

 

 

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

kkhan_123Author
Level 3
December 5, 2022

Hi @krati_garg ,

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

PFB SS:

Thanks for the reply.

kkhan_123Author
Level 3
December 7, 2022

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


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)