Problem/Motivation

The "Send email" action has a recipient field which allows multiple email addresses to be entered. The help states "Separate recipients with a comma.".

The validation performed on the field doesn't take this into account.

Steps to reproduce

Create a new action "Send email", fill in all the fields. In the recipient field, add multiple valid email addresses separated by a comma, click "Save".

Proposed resolution

Split the field value on a comma and loop through the results, validating each one.

This shouldn't break anything as all existing values in the field would still validate.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3307187

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

imclean created an issue. See original summary.

imclean’s picture

Status: Active » Needs review
StatusFileSize
new1.43 KB
abhijith s’s picture

StatusFileSize
new517.67 KB
new1.88 MB

Applied patch #2 on 9.4.x.Multiple email addresses are accepted in the recipient field after applying this patch.

Before patch:
before

After patch:
after

Bushra Shaikh’s picture

StatusFileSize
new84.75 KB
new539.65 KB

Verified and tested patch #2 on the drupal 9.4.x-dev version and the patch applied successfully and looks good to me.

Testing Steps:

  1. Install drupal 9.4.x-dev version.
  2. Install the Action module.
  3. Goto admin/config/system/actions/add/action_send_email_action
  4. Enter the multiple email ids in the recipient field and send.
  5. An error message will be displayed.
  6. Apply the patch and clear the cache.
  7. Again enter the multiple email ids in the recipient field and send.


Testing Results:

After applying the patch multiple email addresses are accepted in the recipient field
We can move this ticket to RTBC.

mitthukumawat made their first commit to this issue’s fork.

smustgrave’s picture

Version: 9.4.x-dev » 10.1.x-dev
Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative, +Needs tests

D10 version needed
At this time we would need a D10.1.x patch or MR for this issue.

imclean’s picture

Status: Needs work » Needs review
StatusFileSize
new1.45 KB
imclean’s picture

It looks like $this->t() is being used here now.

gaurav-mathur’s picture

Assigned: Unassigned » gaurav-mathur

Hi i will review this patch.

gaurav-mathur’s picture

Assigned: gaurav-mathur » Unassigned
StatusFileSize
new278.17 KB
new62.17 KB

Applied patch #9 for Drupal 10.1.x version and working fine. adding screenshot for the reference.

himanshu_jhaloya’s picture

Assigned: Unassigned » himanshu_jhaloya
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new141.94 KB

#9 patch applied cleanly on 10.1.x-dev , looks good adding screenshot

quietone’s picture

Status: Reviewed & tested by the community » Needs work

@gaurav-mathur and @himanshu_jhaloya, thank you for your interest in this issue. However, uploading screenshots of a patch applying is never helpful. The testbot tells us if the patch applies. You can find instructions for Review a patch or merge request task in the Contributor guide. The contributor guide also has details for other ways to help.

Reading the issue I see that this has not passed the core gates.

This issue is tagged for tests and that still needs to be done. There is also no code review.

Setting back to NW.

danielveza’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new4.07 KB
new3.37 KB

Done a first review of the patch, it looks good. I made some minimal changes and added a test.

There is a bit of code duplication in the test with creating the plugin and reading the logs, but it hasn't broken the rule of three so I've left it rather than creating private functions.

pameeela credited eleonel.

pameeela credited lucassc.

pameeela’s picture

Closed #284036: Allow multiple recipients in email actions as a duplicate, moving credit.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Confirmed the issue on Drupal 10.
Was not able to add multiple emails
Applied the patch and I can

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Believe it or not but "te,st"@example.com is a valid email address :(

I think we should do a more complicated fix here. I think we need to change it so textfield is a textarea and we enter them 1 one line. And then in the form submit we smoosh them together with a comma.

himanshu_jhaloya’s picture

Assigned: himanshu_jhaloya » Unassigned
danielveza’s picture

StatusFileSize
new4.16 KB

Good catch @alexpott. Lets try this one. Done the suggestion in #27

danielveza’s picture

StatusFileSize
new5.1 KB

Oops! Patch didn't upload

alexpott’s picture

+++ b/core/lib/Drupal/Core/Action/Plugin/Action/EmailAction.php
@@ -124,7 +124,9 @@ public function execute($entity = NULL) {
-    $recipient = PlainTextOutput::renderFromHtml($this->token->replace($this->configuration['recipient'], $this->configuration));
...
+
+    $recipient = PlainTextOutput::renderFromHtml($this->token->replace($recipients, $this->configuration));

@@ -190,9 +192,13 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
+    $recipients = explode("\r\n", $recipients);

PHP_EOL vs \r\n - which one should we use - I think we should look at the paths in block config and do the same.

Also I think we don't need to introduce $recipients variable in EmailAction::execute() - just using a single $recipient variable is fine - even if there are multiple recipients

danielveza’s picture

Status: Needs work » Needs review
StatusFileSize
new5.12 KB
new1.1 KB

Added a patch to address point 1 in #31. Moved to use the same regex that the request path block visibility field uses.

> Also I think we don't need to introduce $recipients variable in EmailAction::execute() - just using a single $recipient variable is fine - even if there are multiple recipients

I didn't address this. The seperate variable is introduced, otherwise the code looks messy IMO

PlainTextOutput::renderFromHtml($this->token->replace(preg_replace("(\r\n?|\n)", ',', $this->configuration['recipient']), $this->configuration));

Happy to be overridden on this point if people disagree

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
Ajeet Tiwari’s picture

Status: Needs work » Needs review
StatusFileSize
new1.96 KB
new4.74 KB

did the required changes.

imclean’s picture

Status: Needs review » Needs work

@Ajeet Tiwari,

did the required changes.

What changes? You've changed it back from a textarea to a textfield and deleted the test.

Ajeet Tiwari’s picture

Sorry, i missed that change which i made actually while creating the patch. i will update it in the next patch.

smustgrave’s picture

Hiding patch.

danielveza’s picture

@smustgrave I might be having a case of the monday mornings, but why does this need a reroll?

smustgrave’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll

Could of sworn when I tested #32 was failing to apply. Clearly not the case though

smustgrave’s picture

Wait it doesn’t. Just retested

danielveza’s picture

Issue tags: +Needs reroll

Ah yes you're correct. When I checked this morning tests were still green, other commits since the last test run must have stopped this applying. Thanks for confirming, restoring the needs reroll tag.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new85 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

tanuj.’s picture

Status: Needs work » Needs review
StatusFileSize
new5.11 KB
new1.25 KB

As patch #32 doesn't apply to D10 anymore adding a reroll for it.

error: while searching for:
   * {@inheritdoc}
   */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
    if (!$this->emailValidator->isValid($form_state->getValue('recipient')) && strpos($form_state->getValue('recipient'), ':mail') === FALSE) {
      // We want the literal %author placeholder to be emphasized in the error message.
      $form_state->setErrorByName('recipient', $this->t('Enter a valid email address or use a token email address such as %author.', ['%author' => '[node:author:mail]']));
    }
  }


error: patch failed: core/lib/Drupal/Core/Action/Plugin/Action/EmailAction.php:190
error: core/lib/Drupal/Core/Action/Plugin/Action/EmailAction.php: patch does not apply

Status: Needs review » Needs work

The last submitted patch, 43: 3307187-43.patch, failed testing. View results

tanuj.’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs reroll

Thanks for the reroll!

Am able to add multiple recipients now.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/tests/Drupal/KernelTests/Core/Action/EmailActionTest.php
@@ -64,4 +63,41 @@ public function testEmailAction() {
+    // Ensure that the email sending is logged.
+    $log = \Drupal::database()
+      ->select('watchdog', 'w')
+      ->fields('w', ['message', 'variables'])
+      ->orderBy('wid', 'DESC')
+      ->range(0, 2)
+      ->execute()
+      ->fetch();
+
+    $this->assertEquals('Sent email to %recipient', $log->message);
+    $variables = unserialize($log->variables);
+    $this->assertEquals($recipientsExpected, $variables['%recipient']);

Can we use the test mail collector and assert mail trait instead of relying on watchdog entries?

Also can we get red/green patches for the new approach.

Thanks

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Component: action.module » base system

Changing component.

Action module is approved for removal. See #3266458: [Policy] Deprecate Action (UI) module in D10 and move to contrib in D11

asad_ahmed’s picture

Status: Needs work » Needs review
StatusFileSize
new7.04 KB
new4.83 KB

I have modified the code to use test mail collector and assert mail trait instead of watchdogs entries. Can you please review if it works? Thanks

Status: Needs review » Needs work

The last submitted patch, 50: 3307187-50.patch, failed testing. View results

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.