I want to create new accounts based on nodes created by anonymous users via Mailhandler. I understand from an issue thread this will not be added to Mailhandler.

I got a comment from a well respected user who suggested using Mailhandler + Rules so am pursuing it. http://drupal.org/node/977434

Rules does have an action for Create a User but it would seem to require a token for the user email address and I do not know how to get that from Mailhandler. I would think it would be possible as part of the Command Line process per mailbox.

If anyone has accomplished this please comment. Thank you.

Comments

itserich’s picture

This is the error message I am getting from the Devel module when the Rule is invoked:

63.232 ms Action execution: "Create a user"
64.373 ms No appropriate mail address. No user has been created.

Is there a way to get the sending email address and use it as a sort of token to create an email address?

Need something to create a user name also. I used node id token.

summit’s picture

Subscribing, needing same functionality,
greetings, Martijn

end user’s picture

This looks like exactly what I was looking for when creating new users from external scripts like shopping carts.

cor3huis’s picture

IDEA: If Rules and actions etc. do not work one could create a module from the Listhandler and only use the code that creates a users. Or modify listhandler in such a way that there is a new option e.g. only create user.

ilo’s picture

Component: User interface » Documentation

Guys, this for me looks like a good document about how to acomplish it. @itserich, you are the one closer to a solution, can you provide detailed steps to how reach that situation? it is very dificult to provide support to something like this considering the ammout of options and modules (or flows) involved, things don't come up to mind just reading two log lines ;)

jdotti’s picture

Subscribe
JD

itserich’s picture

I did not figure this out, and have not needed it so stopped trying.

This is the Rules module: http://drupal.org/project/rules

It allows automatic response to a variety of situations, and is about as useful as Views, Panels, and a few other key modules.

Login One Time may also help: http://drupal.org/node/1037956

kbasarab’s picture

subscribe

Encarte’s picture

Version: 6.x-1.11 » 6.x-2.x-dev
Issue tags: +rules

This would be possible with Rules, but...

Rules needs an email and a login name in order to create a new user account, so the node created by Mailhandler must provide this information. You can get that information into CCK fields which Rules can use, but you need to have this issue fixed first: #1394216: More mapping sources for IMAP headers. With that fixed, it would be very simple.

danepowell’s picture

Neat idea, let me know if you need any help.

Another option would be to write a Mailhandler authentication plugin that creates a user account if one doesn't already exist for an email address. The benefit of this is that the node author would get assigned the new user account at creation time, and no extra CCK fields would be necessary (not sure if Rules can set the node author to be the new user account).

Encarte’s picture

As to #1394216: More mapping sources for IMAP headers, I'm not a developer, Dane, so, unfortunately, I'm the one who wont be able to help. All I can do is test how the code behaves with Rules and write a how-to afterwords.

Rules can indeed set the node author to be the new user account (just as long as you have Token module), but the other option you describe (writing a Mailhandler authentication plugin) sounds more promising in what concerns performance. Rules can be quite heavy and demanding, and if you have a cron run throwing 10, 20 or more nodes into a user creation rule, you better have a good VPS or dedicated server, because a simple hosting or even a basic VPS probably isn't going to cut it.

In addition, the Mailhandler plugin option would be more site builder friendly, since it wouldn't require Rules and Token, let alone having to know how to build the rule (which seems to be complicated enough to actually be the issue here). That option would make Mailhandler self-sufficient.

eloivaque’s picture

my option

Edit this file sites/all/modules/contrib/mailhandler/plugins/authenticate_plugin/MailhandlerAuthenticateDefault.class.php

<?php
/**
 * @file
 * MailhandlerAuthenticateDefault class.
 */

class MailhandlerAuthenticateDefault extends MailhandlerAuthenticate {

  public function authenticate(&$message, $mailbox) {
    
    list($fromaddress, $fromname) = mailhandler_get_fromaddress($message['header'], $mailbox);
    if ($from_user = user_load(array('mail' => $fromaddress))) {
      $message['authenticated_uid'] = $from_user->uid;
    }
    else {
      // Authentication failed.  Try as anonymous.
            
      $name = substr($fromaddress, 0, strpos($fromaddress,'@'));
      $data = array(
          'name' => $name,
          'pass' => 'password',
          'mail' => $fromaddress,
          'init' => $fromaddress,
          'status' => 1,
        );
        $user = user_save('',$data);
      $message['authenticated_uid'] = $user->uid;
    }
  }

}
danepowell’s picture

FYI, in 6.x-2.5, you can now map the name and email address of a sender separately. Don't know if that helps or not.

danepowell’s picture

Title: using Rules to create new user account based on node creation via Mailhandler - how? » Create new user accounts for anonymous senders
Status: Active » Fixed

Looks like you figured something out. I still think the best solution to this would be to write a custom authentication plugin. Failing that, you could also store the sender name and email address in hidden fields on the created node, then use Rules to create an account based on those fields. But the node will still belong to the anonymous user.

Status: Fixed » Closed (fixed)
Issue tags: -rules

Automatically closed -- issue fixed for 2 weeks with no activity.