def __call__(self): # get the recipients recipient_resolver = IRecipientsResolver(self.event.object) if recipient_resolver: recipients = recipient_resolver.recipients() mailhost = aq_inner(self.context).MailHost if not mailhost: raise ComponentLookupError, 'You must have a Mailhost utility to \ execute this action' urltool = getToolByName(aq_inner(self.context), "portal_url") portal = urltool.getPortalObject() email_charset = portal.getProperty('email_charset') obj = self.event.object interpolator = IStringInterpolator(obj) source = self.element.source if source: source = interpolator(source).strip() if not source: # no source provided, looking for the site wide from email # address from_address = portal.getProperty('email_from_address') if not from_address: raise ValueError, 'You must provide a source address for this \ action or enter an email in the portal properties' from_name = portal.getProperty('email_from_name') source = "%s <%s>" % (from_name, from_address) # prepend interpolated message with \n to avoid interpretation # of first line as header message = "\n%s" % interpolator(self.element.message) subject = interpolator(self.element.subject) for email_recipient in recipients: mailhost.secureSend(message, email_recipient, source, subject=subject, subtype='plain', charset=email_charset, debug=False, ) return True
def __call__(self): # get the recipients recipient_resolver = IRecipientsResolver(self.event.object) if recipient_resolver: recipients = recipient_resolver.recipients() mailhost = aq_inner(self.context).MailHost if not mailhost: raise ComponentLookupError, 'You must have a Mailhost utility to \ execute this action' source = self.element.source urltool = getToolByName(aq_inner(self.context), "portal_url") portal = urltool.getPortalObject() email_charset = portal.getProperty('email_charset') if not source: # no source provided, looking for the site wide from email # address from_address = portal.getProperty('email_from_address') if not from_address: raise ValueError, 'You must provide a source address for this \ action or enter an email in the portal properties' from_name = portal.getProperty('email_from_name') source = "%s <%s>" % (from_name, from_address) obj = self.event.object event_title = safe_unicode(obj.Title()) event_url = obj.absolute_url() message = self.element.message.replace("${url}", event_url) message = message.replace("${title}", event_title) subject = self.element.subject.replace("${url}", event_url) subject = subject.replace("${title}", event_title) for email_recipient in recipients: mailhost.secureSend(message, email_recipient, source, subject=subject, subtype='plain', charset=email_charset, debug=False, ) return True