How to send an email to an address submitted via form in a component? | Community
Skip to main content
Level 2
January 24, 2025
Solved

How to send an email to an address submitted via form in a component?

  • January 24, 2025
  • 2 replies
  • 614 views

In this form I have text inputs and an email field. The intention is to send the results of these fields to the email written in the form when you press the send button.

Best answer by ayush-anand

Hi @vodjakxa 

Create a servlet to handle the form data processing. The servlet will:

  1. Extract the submitted input data from the form.
  2. Use the email address entered in the form as the recipient.
  3. Send an email containing the form details.

This approach is explained in detail in this blog, which provides guidance on sending emails upon form submission.

https://medium.com/@toimrank/aem-email-custom-template-style-and-attachment-d4c0a196ec98

 

Regards

Ayush

2 replies

ayush-anand
ayush-anandAccepted solution
Level 4
January 24, 2025

Hi @vodjakxa 

Create a servlet to handle the form data processing. The servlet will:

  1. Extract the submitted input data from the form.
  2. Use the email address entered in the form as the recipient.
  3. Send an email containing the form details.

This approach is explained in detail in this blog, which provides guidance on sending emails upon form submission.

https://medium.com/@toimrank/aem-email-custom-template-style-and-attachment-d4c0a196ec98

 

Regards

Ayush

VodjakxaAuthor
Level 2
January 24, 2025

Thanks for the reply.

I was looking for a simpler and more immediate method, without having to create new dependencies, but possibly a function already integrated with AEM.

AmitVishwakarma
Community Advisor
Community Advisor
February 2, 2025

To send an email via a form in AEM:
1. Create a Servlet to handle the form submission and send the email:
        - Capture form data (like email, subject, message).
        - Use Day CQ Mail Service to send the email. Form HTML (example):

2.Form HTML (example):

<form action="/bin/send-email" method="post"> <input type="email" name="email" placeholder="Recipient Email" required /> <input type="text" name="subject" placeholder="Subject" required /> <textarea name="message" placeholder="Message" required></textarea> <button type="submit">Send</button> </form>

3. Configure SMTP settings in AEM for email sending.

4. Test the form submission