-->

Is there an easy way in Plone to get email notific

2020-03-27 04:22发布

问题:

I want to get email notifications to the portal email address whenever a new user joins the portal.

My guess is that I should code a new product to do that.

Does such product already exist (for Plone 4)?

I checked content rules, but AFAICT it could work only if I made the users contentish themselves with something like membrane/remember, but for my requirements that would be overkill.

回答1:

I don't think such a product already exists.

It should be trivial to create a package that adds a content rule condition, that would let you write a content rule for the Products.PluggableAuthService.interfaces.events.IPrincipalCreatedEvent event.

The Plone knowledgebase documents how to create such a package.



回答2:

You can easily customize the registered.pt template add a simple call to a PythonScript sending out an email through the MailHost api.

Doing a proper customization of plone.app.users.browser.register.py is much more complex.



回答3:

You can also just have login_next traverse to a Controller Python Script (you'll fine other similar ones in the /plone_login area of the core Plone product that end with the extension '.cpy') that you write that sends the email (perhaps notifyMangersUponLogin ) rather than it's default of traversing to login_success.

Then, have your CPT script traverse to login_success to continue the sript/page MVC flow that Plone ships with, if that's what you want.

To leverage Controller Page Templates (.cpt files)/Scripts (.cpy files), it's key to not only copy the custom version of login_next.cpy to your custom product's skin path, but also the login.cpy.metadata file that specifies the success/failure actions of the MVC page/script logic flow.

With Plone 4.0.2, you'll find the Plone login-related scripts/templates under a path such as: /buildout-cache/eggs/plone-4.0.2-py2.6.egg/Products/CMFPlone/skins/plone_login relative to your buildout structure.



回答4:

If you want to do it the right way, follow Martijn's directions above. If you want another dirty solution, do the following:

  1. make a copy of register.cpy
  2. insert the following code:

    context.MailHost.send('Content-Type: text/plain\n\n' + 'User has registered: ' + str(username),
    mfrom='me@gmail.com',
    mto='you@gmail.com', subject='User Registration', )