Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Want to send email to a user account. Have the user account object, it of course has the account.mail.value which is the account email address.
However, the Rules interface complains that it's expecting a List data type and was given an Email data type when I try to assign account.mail.value as the Send To via a data selector. This is for the System Send Email action.
What is the proper way to send email to a user account?
The exact error message in the interface is:
Expected a list data type for context Send to but got a email data type instead.
The second is: why is message a text field??
Comment | File | Size | Author |
---|---|---|---|
#20 | sendmail-action-plugin.patch | 1.51 KB | n4r3n |
#13 | rules.reaction.forum_your_discussion_was_flagged_inappropriate.yml | 1.56 KB | jmuzz |
Comments
Comment #2
john.oltman CreditAttribution: john.oltman commentedComment #3
alex030 CreditAttribution: alex030 commentedSame problem with node.uid.entity.mail.value on event "After updating content (rules_entity_update:node)".
I want to send an email to the author of a node after update.
With node.uid.entity.mail.value i become the same error message.
With node.uid.entity.mail i can save the rule with no error but if a node is updated no email is send.
So i checked out the logs and saw the message "Successfully sent email to" but i know that it should be for example "Successfully sent email to test@test.com".
The account email is missing in the log message and maybe if the rule action is processed?
Comment #4
alanpeart CreditAttribution: alanpeart commentedWas this ever resolved? I am getting the same problem. I want to email a user after they save a node, and whichever value I choose has a problem. If I choose node.uid.entity.mail.value I cannot save the rule (error message as above) and if I choose node.uid.entity.mail I can save the rule but the email is not sent.
Comment #5
EAnushan CreditAttribution: EAnushan commentedI'm experiencing the same issue. I've tried loading my rule via configuration, and the
context_mapping
doesn't accept lists, so I can't provide a list of data selectors for theto
field in theSystemSendEmail
action.Seems like the patch in https://www.drupal.org/node/2827183 resolves the issue.
Comment #6
lindsay.wils CreditAttribution: lindsay.wils commentedI have encountered this same issue acting on content moderation actions.
As a workaround, you can use the data selection string as a token in the direct input textarea.
Switch to data selection and get your string, in my case content_moderation_state.uid.entity.mail.value
Switch to the direct input mode and paste the string with double braces {{content_moderation_state.uid.entity.mail.value}} to use the token replacement API.
Comment #7
blacklabel_tom CreditAttribution: blacklabel_tom at Reason Digital commentedHi All,
Confirmed the fix in #6 worked for me as a workaround.
Cheers
Tom
Comment #8
yuseferi CreditAttribution: yuseferi commentedThe same error even testing #6 with {{comment.entity_id.entity.uid.entity.mail.value}}, but not working , my drupal version is 8.5.4
Comment #9
TR CreditAttribution: TR commented@zhilevan: Did you enter {{comment.entity_id.entity.uid.entity.mail.value}} in direct input mode? See #2919056: Comment Notify Node Author.
Please export your reaction rule configuration and post it here so we can see exactly what you are doing so we can try to reproduce it.
Comment #10
dureaghin CreditAttribution: dureaghin commentedHi All,
If someone is looking for a solution for Webform, this works: {{webform_submission.uid.entity.mail.value}}
You may need to apply this patch too: 2827183
Thanks,
Alex.
Comment #11
jmuzz CreditAttribution: jmuzz commentedThis does not seem to work for the flag module. I didn't expect the author entity here to be any different, but I tested posting comments on the same node using these suggestions and that does work for me.
For flagging what I tried was {{ flagging.flagged_entity.entity.uid.entity.mail.value }} and a few similar things. What that gave me was:
Recoverable fatal error: Object of class Drupal\Core\Field\FieldItemList could not be converted to string in Drupal\syslog\Logger\SysLog->log() .
Which I guess is a problem trying to record the error. On next page load I get what I think is the "real" error. To summarize, somehow what this sends to the first argument of Drupal\rules\Plugin\RulesAction\SystemSendEmail->doExecute() is not a string, not an array, but an object (FieldItemList).
Still trying to find a workaround.
Comment #12
TR CreditAttribution: TR commented@jmuzz: You need to export your Rule and post it here.
Comment #13
jmuzz CreditAttribution: jmuzz commented@TR I mean these are just hacks for during the development of the typed data solution. All of this is going to be obsolete. I don't want to distract from the real development effort. I will post a solution if I find it.
Here's the export but to even add the condition in it you have to butcher the module with the hack I posted in the other thread (not recommended).
Comment #14
jmuzz CreditAttribution: jmuzz commentedAnd here it is, in Drupal\rules\Plugin\RulesAction\SystemSendEmail.php .
This will allow messages to be sent to the owner of a flagged node with
{{ flagging.flagged_entity.entity.uid.entity.mail.value }}
Use only as a last resort, people. This isn't going to be committed.
Comment #15
TR CreditAttribution: TR commentedThanks for the export - that clarified for me exactly what you're doing and which components you're using.
So #11 - #14 is unrelated to this issue, and is not a problem with Flag either. What you're seeing is the bug in #2927132: List of conditions includes Core conditions which do not work with Rules. Specifically, Rules conditions are not the same as core Drupal conditions, and you can't use core Drupal conditions in Rules. The CTools module appears to provide two core Drupal conditions - those can't be used by Rules. In general, anything that shows up in the "Other" category when you're looking at the conditions is a core Drupal condition and can't be used in Rules. Your export shows me you're trying to use the CTools "entity_bundle" condition. That's why you are getting errors. As you guessed in #2695149: Error when adding condition "Contact form bundle", if you use the Rules condition "Entity is of bundle" instead, then your rule should work properly.
Comment #16
berenddeboer CreditAttribution: berenddeboer at Xplain Hosting commentedI think the later comments have obscured the fact that trying
node.uid.entity.mail.value
does not save.See my rule where I used the above work around:
Comment #17
TR CreditAttribution: TR commentedIt's not obscured, at least to me. The issue is still open and marked as a bug because it's still a problem. However, it is really a UI/UX bug more than anything.
Specifically,
node.uid.entity.mail.value
is a string object, so Rules is correct in not allowing that to be used in the DATA SELECTOR for this action as the Sendmail "To:" address, because "To:" requires an array ('list' datatype) as input. (Multiple e-mail "To:" addresses are allowed!). When using the data selector, strict typing is mandated to ensure that the data may be used. The UI bug would be thatnode.ui.entity.mail
, which is an 'email' datatype (note, without .value at the end), SHOULD be allowed - the "To:" field should accept either an array or a single object of the 'email' datatype when in data selector mode. It does not currently - it requires an array, which we don't have.The "workaround" isn't really a workaround, it's the correct way to do things in this case. If you don't have an object that contains a 'list' of 'email' objects, then you can't use the data selector but you can/should use a token in direct input mode. Using direct input mode, the token
{{node.uid.entity.mail.value}}
resolves to a text string, and text strings are the ONLY things allowed in direct input mode.So the sendmail action works, but the UI is fragile and unhelpful and doesn't deal gracefully with errors. Completion of the UI is milestone 3 out of 3 tasks needed to be finished before Rules goes into beta. If getting this done is important to you, please help out with the development or support the developers!
Comment #18
imperator_99 CreditAttribution: imperator_99 commentedHi all,
I had a bit of trouble getting this to work too, but it turns out that I was putting spaces around the inside of my token, thinking it was like any old Twig token:
{{ node.uid.entity.mail.value }}
But @TR is exactly correct, and the actual token is
{{node.uid.entity.mail.value}}
. Once I got rid of the spaces, it all worked perfectly.Cheers,
Jesse.
Comment #19
TR CreditAttribution: TR commentedIt should work just fine with spaces - there are automated test cases to ensure that spaces are ignored.
Comment #20
n4r3nI hope this patch helps.
Comment #21
TR CreditAttribution: TR commentedThis will be resolved by #2723259: Allow single-valued data selector input to be passed as an array for 'multiple' context fields
Comment #22
VasyOK CreditAttribution: VasyOK commentedAfter applyng patch #20 on latest dev of Rules its impossible to add action.
Comment #23
shradhaG CreditAttribution: shradhaG commentedHi,
I can confirmed the fix in #6 worked for me as a workaround. You need to switch to direct input mode and add your mail value in
{{node.field_mail.value}} in this format. And you are done. :)
Thanks.