-1

I was reading the following about how to use apostrophe-email module for password reset:

However, I wonder if this module will also send a confirmation/activation email to new users with account details, once any user with admin permissions creates their account on their behalf.

Otherwise, any suggestion/recommendation on how to achieve this?

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
D Ramirez
  • 49
  • 7

1 Answers1

0

The apostrophe-email module implements the email method that is available to all modules. Please see the [https://apostrophecms.org/docs/tutorials/howtos/email.html](apostrophecms email HOWTO) for more information about that.

This module is focused on one job - delivering email - and doesn't specifically have anything to do with account creation. And while the apostrophe-login module has a password reset feature that sends email, it doesn't currently send email on account creation. However, you can do that yourself by writing an afterInsert method for the apostrophe-login module at project level in your own code:

// in lib/modules/apostrophe-users/index.js
module.exports = {
  email: {
    // default "from" address for this module
    from: 'example@example.com'
  },
  construct: function(self, options) {
    self.afterInsert = function(req, piece, options, callback) {
      return self.email(req, 'emailInserted', {
          piece: piece
        }, {
          // can also specify from and other
          // valid properties for nodemailer messages here
          to: piece.email,
          subject: 'A new account was created'
        },
        callback
      );
    };
  }
};

This code is lifted almost without modification from an example in the email tutorial for sending email when a different kind of piece is inserted. That works because users are pieces too.

Note that the password is not exposed here. For security reasons it is deleted from the object pretty quickly. You should never email a password.

Tom Boutell
  • 7,281
  • 1
  • 26
  • 23