Send Email Notification when Object Submitted
By default, plone offers you a review portlet where you are able to see which objects have been submitted by members. This is convenient if you visit the site many times a day. It falls short if you do not make frequent visits to your website, and will never be notified when an object has been submitted for approval. The easiest way around this is to receive an email notification whenever an object is submitted.
In order to do this, you will need to create a 'Workflow Script'.
- Go into the portal_workflow section of your plone site.
- Choose the appropriate workflow, in most cases this will be plone_workflow
- Click the 'Scripts' tab.
- Add a new Script (Python), name it appropriately, then insert the following code:
obj = state_change.object
mship = context.portal_membership
mhost = context.MailHost
adminEmail = context.email_from_address
to_string = 'portaladmin@domain.com'
for user in mship.listMembers():
if "Reviewer" in mship.getMemberById(user.id).getRoles():
if user.email:
to_string = to_string + ',' + user.email
message = """
From: %s
To: %s
Subject: New object submitted
%s
"""
msg = message % (
administratorEmailAddress,
to_string,
obj.absolute_url()
)
mhost.send(msg)
Once, you have done this, follow these steps below to assign your script to a workflow transition:
- Go back into the workflow you are working on, then choose the 'Transitions' tab.
- Choose the 'Submit' transition
- For 'Script (after)', select the script that you added in the previous steps.
Need assistance with your project? Universal Web Services can help.
Contact us to request a quote.