Changeset 3535 in products for quintagroup.mailer/branches
- Timestamp:
- Aug 28, 2012 10:02:35 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.mailer/branches/devel/quintagroup/mailer/actions/mail.py
r3527 r3535 2 2 from OFS.SimpleItem import SimpleItem 3 3 from zope.component import adapts, getUtility 4 from zope.component.interfaces import ComponentLookupError5 4 from zope.interface import Interface, implements 6 5 from zope.formlib import form 7 6 from zope import schema 8 7 9 from plone.app.contentrules.browser.formhelper import AddForm, EditForm 8 from plone.app.contentrules.browser.formhelper import AddForm, EditForm 10 9 from plone.contentrules.rule.interfaces import IRuleElementData, IExecutable 11 10 … … 14 13 from Products.CMFPlone.utils import safe_unicode 15 14 16 from zope.sendmail.interfaces import I QueuedMailDelivery, IMailDelivery15 from zope.sendmail.interfaces import IMailDelivery 17 16 import email.MIMEText 18 17 import email.Header … … 20 19 attr_rexp = re.compile("\$\{item\.(\w+)\}") 21 20 21 22 22 class IMailAction(Interface): 23 23 """Definition of the configuration available for a mail action 24 24 """ 25 subject = schema.TextLine(title=_(u"Subject"), 26 description=_(u"Subject of the message. ${title} replaced with object title"),27 25 subject = schema.TextLine(title=_(u"Subject"), description=_( 26 u"Subject of the message. ${title} replaced with object title"), 27 required=True) 28 28 29 groups = schema.TextLine(title=_(u"Recipients"), 30 description=_("The group of users for whom you want to"31 "send this message.To send it to different groups, just separate them with ,"),32 29 groups = schema.TextLine(title=_(u"Recipients"), description=_( 30 "The group of users for whom you want to send this message. " 31 "To send it to different groups, just separate them with ,"), 32 required=True) 33 33 34 message = schema.Text(title=_(u"Message"), 35 description=_(u"Type in here the message that you \ 36 want to mail. Some defined content can be replaced: ${title} will be replaced \ 37 by the title of the item. ${url} will be replaced by the URL of the item.\ 38 ${description} will be replaced by the description of the item.\ 39 ${item.<attribute>} will be replaced by the attribute of the item."), 40 required=True) 34 message = schema.Text(title=_(u"Message"), description=_( 35 u"Type in here the message that you want to mail. Some defined " 36 "content can be replaced: ${title} will be replaced by the title of " 37 "the item. ${url} will be replaced by the URL of the item. " 38 "${description} will be replaced by the description of the item. " 39 "${item.<attribute>} will be replaced by the attribute of the item."), 40 required=True) 41 41 42 42 43 class MailAction(SimpleItem): … … 69 70 self.event = event 70 71 71 72 72 def getEmailAddresses(self, groups): 73 mtool = getToolByName(self.context, 'portal_membership')74 73 users_tool = getToolByName(self.context, 'acl_users') 75 74 addresses = [] … … 84 83 return addresses 85 84 86 87 85 def __call__(self): 88 86 groups = self.element.groups.split(',') 89 recipients = self.getEmailAddresses(groups) # list of email addresses87 recipients = self.getEmailAddresses(groups) # list of email addresses 90 88 91 89 mailer = getUtility(IMailDelivery, 'iw.mailer') … … 101 99 from_address = portal.getProperty('email_from_address') 102 100 if not from_address: 103 raise ValueError , 'You must enter an email in the portal properties'101 raise ValueError('You must enter an email in the portal properties') 104 102 from_name = portal.getProperty('email_from_name') 105 103 source = "%s <%s>" % (from_name, from_address) 106 104 107 105 subject = self.element.subject.replace("${title}", event_title) 108 106 109 107 for attr in attr_rexp.findall(subject): 110 108 if getattr(obj, attr, None) is None: 111 109 continue 112 if callable(getattr(obj, attr)): 110 if callable(getattr(obj, attr)): 113 111 value = safe_unicode(getattr(obj, attr)()) 114 else: 112 else: 115 113 value = safe_unicode(getattr(obj, attr)) 116 114 subject = subject.replace("${item.%s}" % attr, unicode(value)) … … 122 120 if getattr(obj, attr, None) is None: 123 121 continue 124 if callable(getattr(obj, attr)): 122 if callable(getattr(obj, attr)): 125 123 value = safe_unicode(getattr(obj, attr)()) 126 else: 124 else: 127 125 value = safe_unicode(getattr(obj, attr)) 128 126 body = body.replace("${item.%s}" % attr, unicode(value)) 129 127 130 128 for userid, recipient in recipients: 131 129 msgbody = body.replace('${userid}', userid) … … 137 135 mailer.send(source, [recipient], msg.as_string()) 138 136 return True 137 139 138 140 139 class MailAddForm(AddForm): … … 152 151 return a 153 152 153 154 154 class MailEditForm(EditForm): 155 155 """ … … 160 160 description = _(u"A mail action can mail different recipient.") 161 161 form_name = _(u"Configure element") 162
Note: See TracChangeset
for help on using the changeset viewer.