0

I have create a new content type with a field of email. In this field I put the email address of the person I want.

The case is: I want every time the node of this content type updated, to send an email to the address from the email field.

With Rules module I cannot find a proper way to make it work because Rules are on a very early point of development.

There is two problems with rules: 1st - I have create a simple action to send an email every time the node is updated. This is work fine. When I create a condition "Node is of type" and select only one content type the sending email action is still working for all content types.

2nd - I cannot find any proper method for what suppose to write to the reciptient field to send the email to the address from the email field.

Can any one help? Any thoughts?

  • try drupal.org/project/business_rules – pinueve Apr 28 at 21:56
  • Business Rules are not working properly. I have try the module in 3 defferent installations of drupal and every time I create a rules it directing to install drupal.... – Dimitris T. Apr 28 at 22:04
  • 1
    At structure (admin menu), there is a "Contact Forms" option where you can create new forms and is basically what I think you would need. – Hawk Apr 28 at 23:45
  • No , I want to do it automatically via Rules – Dimitris T. Apr 29 at 14:56
  • See if this is of any help drupal.org/project/rules/issues/2852342 #3 gives a solution that seems related to your case – GiorgosK May 26 at 17:22
1

First, use the -dev version of Rules.

Second, always use the "Show a message on the site" action for testing. This is a LOT easier to debug than "Send email". You can use tokens in the message to test that the values are what you expect them to be, then when you get the right values you can use the email action with those same tokens in your email.

Third, always clear your caches after making changes to a rule.

Fourth, the issue queue contains many complete examples you can use. For instance, here is an example of how to show a system message when an "article" type node is created (from https://www.drupal.org/project/rules/issues/2852342). Try this you will see that "Node is of Type" DOES work to restrict the type - the message will never be shown if you create a node that is not an article:

uuid: c1b8486c-a96b-4f53-903a-8a08cb85355d
langcode: en
status: true
dependencies: {  }
id: test_rule
label: 'Test rule'
events:
  -
    event_name: 'rules_entity_insert:node'
description: ''
tags: {  }
config_version: '3'
expression:
  id: rules_rule
  uuid: f8e466d6-51d6-41ea-93f1-34436470f3c3
  conditions:
    id: rules_and
    uuid: 7776a869-e0c6-4499-b09e-da727722213e
    conditions:
      -
        id: rules_condition
        uuid: 6bf893f5-7bcf-420c-9a62-7e1cb9a884f6
        context_values:
          types:
            - article
        context_mapping:
          node: node
        context_processors:
          types:
            rules_tokens: {  }
        provides_mapping: {  }
        condition_id: rules_node_is_of_type
        negate: false
  actions:
    id: rules_action_set
    uuid: f0bcccfd-685f-4a74-a4fd-0d36b540037a
    actions:
      -
        id: rules_action
        uuid: ec599dbc-cb40-448b-b37b-129d956c2eb7
        context_values:
          message: '<b>Test rule triggered</b> {{ node.title }}'
          type: status
          repeat: false
        context_mapping: {  }
        context_processors:
          message:
            rules_tokens: {  }
          type:
            rules_tokens: {  }
          repeat:
            rules_tokens: {  }
        provides_mapping: {  }
        action_id: rules_system_message

And finally, here's a complete example for how to send e-mail to an address contained in a field value. This example assumes you have a node content type with machine name "email" which has a single-valued required field of type "email" named "field_email".

uuid: bc3fb7fd-0cbd-416c-8b71-9d6b710eb0ce
langcode: en
status: true
dependencies: {  }
id: send_email_when_content_of_type_email_is_created
label: 'Send email when content of type "email" is created'
events:
  -
    event_name: 'rules_entity_insert:node'
description: ''
tags: {  }
config_version: '3'
expression:
  id: rules_rule
  uuid: 265d153c-9ce9-4250-a1b7-b8670be7826c
  conditions:
    id: rules_and
    uuid: 4f570c4e-3558-4628-96dc-aebb7b6d9e65
    conditions:
      -
        id: rules_condition
        uuid: 8014e5b0-680d-46c3-94fc-0785022447ca
        context_values:
          types:
            - email
        context_mapping:
          node: node
        context_processors:
          types:
            rules_tokens: {  }
        provides_mapping: {  }
        condition_id: rules_node_is_of_type
        negate: false
  actions:
    id: rules_action_set
    uuid: 25127564-6ab9-4587-b1b9-9336781aab9e
    actions:
      -
        id: rules_action
        uuid: 16f51441-39e8-4872-a3c2-e4e12a339f1e
        context_values:
          message: 'Email is {{ node.field_email.value }}'
          type: status
          repeat: false
        context_mapping: {  }
        context_processors:
          message:
            rules_tokens: {  }
          type:
            rules_tokens: {  }
          repeat:
            rules_tokens: {  }
        provides_mapping: {  }
        action_id: rules_system_message
      -
        id: rules_action
        uuid: 2c636fe9-9b9a-46b8-b930-81b9730f5ac2
        context_values:
          to:
            - '{{ node.field_email.value }}'
          subject: 'An Email node was created'
          message: 'An Email node was created'
          reply: ''
          language: ''
        context_mapping: {  }
        context_processors:
          to:
            rules_tokens: {  }
          subject:
            rules_tokens: {  }
          message:
            rules_tokens: {  }
          reply:
            rules_tokens: {  }
          language:
            rules_tokens: {  }
        provides_mapping: {  }
        action_id: rules_send_email

If you import these Rules onto your site and inspect how they're constructed they will help you learn how to do this yourself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.