Attention

This document was written for an unsupported version of Plone, Plone 2.0.x, and was last updated 256 days ago.

For more information, see the version support policy.

To learn how to upgrade to the current version of Plone, read the upgrade manual.

eMail upcoming events to plone group

by dpetersen — last modified Sep 04, 2012 03:33 PM
a python script to notify all members of a Plone group of upcoming events via email
  • create a plone group 'event-notification' and add users to this group
  • go to ZMI and create a "Script (Python)" with ID eventNotifier and paste the content below and modify the tuple NotifyDaysAhead as appropriate
  • set a proxy role = owner for eventNotifier
  • execute the script via cron job once a day after midnight. (for example 'wget http://yoursite/eventNotifier > /dev/null') or use ZopeScheduler (http://www.google.com/search?q=ZopeScheduler)
# notifyEvents: notify all members of a plone group of upcoming events

# Notify all members of 'event-notification' 7 days and a second time 1 day ahead.
NotifyDaysAhead = 7,1

# formatting of Message Header and Body
msgheader = """
From: %s
To: %s
Subject: A new event from fly-sgi.org in %s day(s)
"""

msgbody = """
This event is upcoming:
Title: %(Title)s
Event Type: %(Subject)s
Start: %(StartDate)s (US Pacific Time)
End: %(EndDate)s
Location: %(Location)s
Contact: %(ContactName)s
Contact email: %(ContactEmail)s
Contact Phone: %(ContactPhone)s
URL: %(EventURL)s
URL to this item: %(absolute_url)s
Description: %(Description)s
"""

# get email addresses of members of event-notification
grp = context.portal_groups.getGroupById('event-notification')
if grp == None: return
to_emails = ''
for user in grp.getGroupMembers():
  to_emails += user.email + ';'

# we could also use zope roles instead of plone groups
#for user in context.portal_membership.listMembers():
#  if "MyRole" in context.portal_membership.getMemberById(user.id).getRoles()

today = DateTime().Date() # returns a string yyyy/mm/dd
today = DateTime(today)   # converts the string back to a date object
for days in NotifyDaysAhead:
  # query portal catalog index for upcoming events with a start date range of 1 day #  review_state='published',
  query=context.portal_catalog(portal_type='Event',
                          start={'query': (today+days,today+days+1),
                          'range': 'min:max'})

  # re-query each object with the getObjecy method to be able to query metadata
  for ev in query:
    evobj = ev.getObject()
    mydict = {}
    mydict['absolute_url'] = evobj.absolute_url()
    for y, z in evobj.getMetadataHeaders():
      mydict[y] = z

    # this could be extended if events in certain plone older should be treated differently
    #if evobj.aq_parent.getId() == 'mySpecialFolder': treatMeDifferently()

    # concat Message and send
    msg = msgheader % (context.email_from_address,to_emails,days) + msgbody % mydict
    context.MailHost.send(msg)
    print "Notification sent to " + to_emails + " : \n" + msg

return printed

Contribute

Something wrong or out of date? Anybody can edit or create a new article in the knowledge base. Simply create an account on this site, log in, and click the Edit button to contribute.