Problem/Motivation

Using Drupal 7.

Want to create an advanced action in configuration:actions to Send Email.

When I do that, in the Recipient Field I want to add a tokenized field from the list below. It's a field I created with the "Email Field" module. It inserts the tokenized field when I click on it. The tokenized field is called [node:field-email].

When I submit the page however, it gives error: "Enter a valid email address or use a token e-mail address such as [node:author:mail]." But I am using a token email address, one that is created with the email field module.

Why doesn't it like my email field token?

I'm otherwise stuck with this because if I try to use Rules instead, there are bugs with Rules 7 to the point that I can't send an email that way either because I get fatal errors.

Steps to reproduce

Proposed resolution

Remaining tasks

Reroll patch
Write a test
Review
Commit

User interface changes

API changes

Data model changes

Release notes snippet

Comments

jeremyll’s picture

subscribing

dave reid’s picture

Project: Token » Drupal core
Version: 7.x-1.0-beta1 » 7.x-dev
Component: Token Actions » system.module
Priority: Critical » Normal

That validation is performed by core's system module, not Token. And this is *definitely* not a critical issue. Please read http://drupal.org/node/45111 for more information on issue priorities.

wiifm’s picture

StatusFileSize
new852 bytes

Having the same issue here, we created custom tokens, and the form was refusing to save

Found the offending code on line 3127 of system.module:

/**
 * Validate system_send_email_action form submissions.
 */
function system_send_email_action_validate($form, $form_state) {
  $form_values = $form_state['values'];
  // Validate the configuration form.
  if (!valid_email_address($form_values['recipient']) && strpos($form_values['recipient'], ':mail') === FALSE) {
    // We want the literal %author placeholder to be emphasized in the error message.
    form_set_error('recipient', t('Enter a valid email address or use a token e-mail address such as %author.', array('%author' => '[node:author:mail]')));
  }
}

So it appears, as our custom token does not have the string ':mail' in it, it is being rejected.

Surely a better solution would be to check for either:

a) valid email address
b) valid token

And leave it up to the token creator to ensure the token conforms to the correct syntax for having email address(es)?

Attached is a patch, that proposes solution b) (patch created from SVN on drupal 7.9 - sorry!)

Anyone core maintainers want to add anything here?

Sean

wiifm’s picture

Status: Active » Needs review

setting tags for review

Status: Needs review » Needs work

The last submitted patch, token-email-1066060.patch, failed testing.

lk7889’s picture

The patch failed but if I manually update the system.module with the code in the patch, it works like a charm for me.

wiifm’s picture

StatusFileSize
new916 bytes

New patch made from git, this should apply

wiifm’s picture

Status: Needs work » Needs review
irunflower’s picture

Status: Needs review » Closed (fixed)

Tested patch in #7 with Drupal 7.14:

patching file modules/system/system.module
patch unexpectedly ends in middle of line
Hunk #1 succeeded at 3156 with fuzz 1 (offset 30 lines)

But patch worked, problem solved.

wiifm’s picture

Status: Closed (fixed) » Needs review

@irunflower - if the patch does not work, can you roll another one?

Also if you like the patch, please consider marking it 'Reviewed and Tested by the Community', rather than closing it ;)

irunflower’s picture

Status: Needs review » Reviewed & tested by the community
David_Rothstein’s picture

Version: 7.x-dev » 8.x-dev
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs backport to D7

Looks like this code still exists in Drupal 8, so presumably the bug exists there too. So we need to fix this in Drupal 8 first.

wiifm’s picture

Status: Needs work » Needs review
StatusFileSize
new936 bytes

8.x patch rolled

Status: Needs review » Needs work

The last submitted patch, 13: 1066060-13-token_email_fix.patch, failed testing.

mgifford’s picture

Issue summary: View changes

What happened to function system_send_email_action_validate()? I can't grep it.

Collins405’s picture

Works beautifully, how do we implement this without hacking core?

mgifford’s picture

@Collins405 you are using D7, right?

This has to be fixed first in D8, then it can be backported to D7. That is unless this problem no longer exists in D8.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Component: system.module » action.module
Issue summary: View changes
Issue tags: -action, -send email, -trigger action, -tokenized action, -token node, -recipient field, -recipient email, -email field module, -email field +Bug Smash Initiative, +Needs issue summary update, +Needs tests

From reading the code this problem still exists.

The validation is now in \Drupal\Core\Action\Plugin\Action\EmailAction::validateConfigurationForm and that is where the change suggested in the patch needs to move to. Changing component to Action module. This will also need a test. I've started an update of the IS but it is not complete. Adding tags. And removing unnecessary tags.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

imclean’s picture

There is another problem with EmailAction->validateConfigurationForm(). The recipient field can contain a comma separated list of email addresses, however the email validator used doesn't take that into account.

One solution would be to split on a comma and loop through the addresses, validating each one. But if egulias/EmailValidator supports validating against an email list that might be a better to use that properly.

https://api.drupal.org/api/drupal/vendor%21egulias%21email-validator%21s...

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs work » Postponed

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

This is now Postponed. The status is set according to two policies. The Remove a core extension and move it to a contributed project and the Extensions approved for removal policies.

It will be moved to the contributed Action project when the Drupal 11 branch is open.

Version: 9.5.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. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

andypost’s picture

Component: action.module » system.module
Status: Postponed » Needs work
Related issues: +#3423983: Add cc to core email action

the module moved to contrib project but not actions

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.