Skip to content

feat: Add confirmation email for form respondents#3098

Closed
dtretyakov wants to merge 2 commits intonextcloud:mainfrom
dtretyakov:main
Closed

feat: Add confirmation email for form respondents#3098
dtretyakov wants to merge 2 commits intonextcloud:mainfrom
dtretyakov:main

Conversation

@dtretyakov
Copy link
Copy Markdown

@dtretyakov dtretyakov commented Dec 17, 2025

Implements issue #525 - Send confirmation emails to form respondents after submission.

Features:

  • Add database migration for confirmation email settings (enabled, subject, body)
  • Add confirmation email fields to Form entity
  • Implement email sending with placeholder replacement:
    • {formTitle}, {formDescription} placeholders
    • Field name placeholders (e.g. {name}, {email})
    • Automatic data overview if {data} not in template
  • Add UI in Settings sidebar to configure confirmation emails
  • Automatically detect email field from form submissions
  • Send email using system mail account

Technical changes:

  • Add sendConfirmationEmail() method to FormsService
  • Integrate email sending into notifyNewSubmission() flow
  • Add unit tests for confirmation email functionality
  • Update FormsService constructor with IMailer and AnswerMapper dependencies
  • Update documentation (DataStructure.md, CHANGELOG.en.md)

The feature requires at least one email-validated short text question in the form. Email sending failures are logged but don't break the submission process.

Screenshot 2025-12-19 105758

@Chartman123
Copy link
Copy Markdown
Collaborator

@dtretyakov thanks for you contribution :) Please have a look at the failing checks and fix them :)

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 18, 2025

Codecov Report

❌ Patch coverage is 76.72414% with 27 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lib/Migration/Version050301Date20260413233000.php 0.00% 20 Missing ⚠️
lib/Service/FormsService.php 92.39% 7 Missing ⚠️

📢 Thoughts on this report? Let us know!

@dtretyakov dtretyakov force-pushed the main branch 3 times, most recently from 52d72a9 to 3f94699 Compare December 19, 2025 08:48
@dtretyakov
Copy link
Copy Markdown
Author

@Chartman123 done, it seems that approval is required to re-run remaining checks

@dtretyakov dtretyakov force-pushed the main branch 6 times, most recently from e61e929 to ec01c84 Compare December 20, 2025 12:06
@dtretyakov
Copy link
Copy Markdown
Author

@Chartman123 the tests are green.

I’m not sure who could help reviewing that to proceed further.

@Chartman123
Copy link
Copy Markdown
Collaborator

@dtretyakov I'll have a closer look in the next days :)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 1, 2026

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

@dtretyakov
Copy link
Copy Markdown
Author

@Chartman123 hopefully you are doing well.

Do you need an additional information to proceed further with the review?
Also if you're busy we could also invite another person to review the changes.

@Chartman123
Copy link
Copy Markdown
Collaborator

@dtretyakov just being busy at the moment... the same applies to my co-maintainer. so just give us some more time. :)

Some questions: what do you do if there's more than one e-mail field? also no error checking in the frontend if there's none.

Copy link
Copy Markdown
Collaborator

@susnux susnux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks quite clean but did not review properly yet.
Will do soon!

@Chartman123 Chartman123 added this to the 5.3 milestone Jan 26, 2026
@Chartman123 Chartman123 linked an issue Jan 26, 2026 that may be closed by this pull request
@Chartman123
Copy link
Copy Markdown
Collaborator

  • Send email from form owner's email address

Please use the configured system mail account for sending the mails for privacy reasons, but also for making sure the mail gets sent at all. Most mailservers will check if the sender's address corresponds to the logged on user.

@Chartman123
Copy link
Copy Markdown
Collaborator

Please don't use merge commits, just rebase your branch on main :)

@dtretyakov dtretyakov reopened this Jan 27, 2026
@dtretyakov
Copy link
Copy Markdown
Author

@Chartman123 thank you for the review. I rebased the changes on top of the main branch.

Some questions: what do you do if there's more than one e-mail field? also no error checking in the frontend if there's none.

Now we have the validation when no e-mail fields are present and multiple e-mail fields are available:
no-email
multiple-email

Please use the configured system mail account for sending the mails for privacy reasons, but also for making sure the mail gets sent at all. Most mailservers will check if the sender's address corresponds to the logged on user.

Done, now it uses system mail account

@dtretyakov
Copy link
Copy Markdown
Author

@susnux or @Chartman123 do you have any other ideas to address before the merge?

@Chartman123
Copy link
Copy Markdown
Collaborator

@dtretyakov Could you please move your changes to a branch other than main in your fork? This makes it easier to check out your changes in my local dev environment

Copy link
Copy Markdown
Collaborator

@susnux susnux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this makes sense to me, but from experience with other tables like this it turned out that its not ideal for scaling.

The problem is that many things in the table are only used by few tables but cause huge size of the table like "submission message" or from this PR "confirmation mail body".

Its not a problem introduced with this PR - so we can also do this later!
But just for some feedback here cc @Chartman123

I wonder if we should first - or later - split the table to get some "forms metadata" or similar so that we can put data not needed for every action there.
That would reduce database select latency a lot for large instances (e.g. this information is only needed on edit or insert submit but not for the majority of requests which would just load the form for submitting.

Copy link
Copy Markdown
Collaborator

@susnux susnux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for the pull request itself I think it is quite nice! Good work :)

Just about the email field I am not sure if we should not better explicitly let the creator flag the input field to use.

Comment thread lib/Service/FormsService.php Outdated
}

$emailValue = $answerMap[$questionId][0];
if ($this->mailer->validateMailAddress($emailValue)) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should rather use \OCP\Mail\IEmailValidator for validation

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switched to IEmailValidator

Comment thread lib/Service/FormsService.php Outdated
Comment on lines +813 to +828
// If no email found, cannot send confirmation
if (empty($recipientEmails)) {
$this->logger->debug('No valid email address found in submission for confirmation email', [
'formId' => $form->getId(),
'submissionId' => $submission->getId(),
]);
return;
}

if (count($recipientEmails) > 1) {
$this->logger->debug('Multiple email fields found in submission for confirmation email, using first match', [
'formId' => $form->getId(),
'submissionId' => $submission->getId(),
'emailCount' => count($recipientEmails),
]);
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this is the best way to configure the mail.
I can imagine multiple valid scenarios where you ask for multiple e-mail addresses-

Maybe we can set a flag on such a question? So the form creator can configure which field to use?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a dedicated flag, stored in extra settings

@Chartman123
Copy link
Copy Markdown
Collaborator

let the creator flag the input field to use.

Could be part of the extraSettings

dtretyakov added a commit to dtretyakov/forms that referenced this pull request Apr 13, 2026
- Allow form creators to explicitly select which email field to use for confirmations via the `confirmationEmailRecipient` property.
- Update `FormsService` to rely on the explicit recipient field when multiple email fields are present.
- Display relevant warnings in the settings tab if recipient fields are misconfigured.
- Replace basic email validation with Nextcloud's internal `\OCP\Mail\IEmailValidator`.
- Expand unit tests to verify explicit recipient selection and multi-email field validation logic.
@dtretyakov dtretyakov force-pushed the main branch 2 times, most recently from cdbd2d0 to 0620a2d Compare April 13, 2026 22:08
@dtretyakov dtretyakov closed this Apr 13, 2026
@dtretyakov dtretyakov reopened this Apr 13, 2026
Implements issue nextcloud#525 - Send confirmation emails to form respondents after submission.

Features:
- Add confirmation email settings (enabled, subject, body) to Form entity.
- Implement email sending with placeholder replacement:
  - {formTitle}, {formDescription}
  - Field placeholders based on name or label (e.g. {name}, {email}).
- Allow form creators to explicitly select the recipient email field when multiple email fields are present.
- Add UI in Settings sidebar to configure confirmation emails and recipient selection.
- Replace basic email validation with Nextcloud's internal IEmailValidator.
- Integration with activity notifications and background jobs for file syncing.

Technical changes:
- Database migration for new Form properties.
- Enhanced FormsService with email sending logic and validation.
- Extensive unit and integration tests covering the new functionality.
- Updated API documentation and OpenAPI spec.

Signed-off-by: Dmitry Tretyakov <dtretyakov@gmail.com>
@dtretyakov
Copy link
Copy Markdown
Author

Could you please move your changes to a branch other than main in your fork?

@Chartman123 I created a draft PR with the same changes #3289

Could be part of the extraSettings

Added the dedicated flag confirmationEmailRecipient stored in extraSettings

@Chartman123
Copy link
Copy Markdown
Collaborator

@dtretyakov ok, so we can close this one?

@dtretyakov dtretyakov closed this Apr 14, 2026
@dtretyakov
Copy link
Copy Markdown
Author

Closed in favor of #3289

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Confirmation mail for respondents

3 participants