Answers.Body: <p>The good news is that it is possible to send an email with a one-time login URL using rules. </p>
  
  <p>There is an issue on the rules module for exactly this ability: <a href="https://www.drupal.org/project/rules/issues/1289898" rel="nofollow noreferrer">problem with mail and one-time-login-url</a>. A patch has been created for this issue that generates a new action in rules to generate a one-time login URL variable which you can then use to insert into an email. I updated the <a href="https://www.drupal.org/project/rules/issues/1289898#comment-12882107" rel="nofollow noreferrer">latest version of the patch</a> to work with the most recent dev version of rules.</p>
  
  <p>You will need to access the Drupal user account details in the rule in order to generate the login.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-05T15:16:56.733Z
Answers.Text: Thanks @Ben, this is super helpful! I hadn't found that patch, and this will help us greatly now. 
  As it turned out, we sidestepped the problem just this once by auto-generating a password for the user in Rules and then emailing it to them along with their username. No where near as secure as the one-time-login but for this purpose quite suitable. To generate the password we used: https://drupal.stackexchange.com/a/120661/30379
Answers.UserDisplayName: Andyg8
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-05T06:14:38.980Z
Answers.LastActivityDate: 2019-06-05T06:14:38.980Z
Answers.UserDisplayName: Ben
Body: <p>With Drupal and Civi latest, is it possible to send an email with a one-time login url?</p>
  
  <p>We have a scenario in which an admin grants a membership to a new contact. We want this new contact to automatically be given a new user account, and the correct role for their membership, and then send them an email giving them details about their new membership, as well as how to access their membership materials. (Their membership materials are on Drupal pages that are only visible to that membership's role). </p>
  
  <p>So far we've succeeded in all of the above, using Drupal Rules.</p>
  
  <p>However, to make their life easier I'd like to send them a one-time login so they can quickly make a password and get on with their life!</p>
  
  <p>I'd prefer not to use the Drupal 'New Account' email for this purpose, since that has to be the same for all possible new users of the site. Also, we looked into not creating a user for them, and just sending them to the Drupal new user registration page. But that's clunky and these users are not internet savvy; they get lost. </p>
  
  <p>In Drupal rules' 'Send HTML Email' action there is a token for the one-time user login: civicrm-user:one-time-login-url. However, it's not populated. And inspecting $civicrm_user via php print_r in the email shows no sign of this variable. </p>
  
  <p>I did wonder if CiviRules could do all of the above, but I can't see any way to make a user from it, nor any token for a one-time user login - quite naturally since this would be a Drupal thing. </p>
  
  <p>So... any ideas about how to progress this? I'm grateful for your thoughts.</p>
  
Tags: <drupal><user-account><drupal-rules>
Title: The replacement token civicrm-user:one-time-login-url not working in Drupal Rules emails
ThreadText: # The replacement token civicrm-user:one-time-login-url not working in Drupal Rules emails
  
  (Asked by: username_0 on 2019-05-31)
  
  With Drupal and Civi latest, is it possible to send an email with a one-time login url?
  
  We have a scenario in which an admin grants a membership to a new contact. We want this new contact to automatically be given a new user account, and the correct role for their membership, and then send them an email giving them details about their new membership, as well as how to access their membership materials. (Their membership materials are on Drupal pages that are only visible to that membership's role).
  
  So far we've succeeded in all of the above, using Drupal Rules.
  
  However, to make their life easier I'd like to send them a one-time login so they can quickly make a password and get on with their life!
  
  I'd prefer not to use the Drupal 'New Account' email for this purpose, since that has to be the same for all possible new users of the site. Also, we looked into not creating a user for them, and just sending them to the Drupal new user registration page. But that's clunky and these users are not internet savvy; they get lost.
  
  In Drupal rules' 'Send HTML Email' action there is a token for the one-time user login: civicrm-user:one-time-login-url. However, it's not populated. And inspecting $civicrm\_user via php print\_r in the email shows no sign of this variable.
  
  I did wonder if CiviRules could do all of the above, but I can't see any way to make a user from it, nor any token for a one-time user login - quite naturally since this would be a Drupal thing.
  
  So... any ideas about how to progress this? I'm grateful for your thoughts.
  
  **Tags:** drupal, user-account, drupal-rules
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-06-05. Score: 2 | Accepted answer
  
  The good news is that it is possible to send an email with a one-time login URL using rules.
  
  There is an issue on the rules module for exactly this ability: [problem with mail and one-time-login-url](https://www.drupal.org/project/rules/issues/1289898). A patch has been created for this issue that generates a new action in rules to generate a one-time login URL variable which you can then use to insert into an email. I updated the [latest version of the patch](https://www.drupal.org/project/rules/issues/1289898#comment-12882107) to work with the most recent dev version of rules.
  
  You will need to access the Drupal user account details in the rule in order to generate the login.
  
  > **Comments:**
  > **username_0**: Thanks @username_1, this is super helpful! I hadn't found that patch, and this will help us greatly now.  As it turned out, we sidestepped the problem just this once by auto-generating a password for the user in Rules and then emailing it to them along with their username. No where near as secure as the one-time-login but for this purpose quite suitable. To generate the password we used: https://drupal.stackexchange.com/a/120661/30379  
  
  ---
  
  