- 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