def get_recipients(self): """ The recipients of this mail """ # Try to load data from the target object fieldName = str(self.element.fieldName) obj = self.get_target_obj() attr = getattr(obj, fieldName) if hasattr(attr, "__call__"): recipients = attr() logger.debug("getting e-mail from %s method" % fieldName) else: recipients = attr logger.debug("getting e-mail from %s attribute" % fieldName) # now transform recipients in a iterator, if needed if type(recipients) == str or type(recipients) == six.text_type: recipients = [str(recipients)] if not recipients: return [] return list(filter(bool, recipients))
def __call__(self): ''' Does send the mail ''' mailhost = self.get_mailhost() source = self.get_from() recipients = self.get_recipients() obj = self.event.object interpolator = IStringInterpolator(obj) # No way to use self.context (where rule is fired) in interpolator # self.context in interpolator is the obj given # And having two interpolators is strange, because they # both adapt fully. Unless you can somehow adapt it to # 'firing a rule' event, which isn't available to my knowledge. # Section title/urk subject = self.expand_markers(self.element.subject) message = self.expand_markers(self.element.message) # All other stringinterp subject = interpolator(self.element.subject).strip() message = interpolator(self.element.message).strip() email_charset = self.portal.getProperty('email_charset') for email_recipient in recipients: logger.debug('sending to: %s' % email_recipient) try: # sending mail in Plone 4 mailhost.send(message, mto=email_recipient, mfrom=source, subject=subject, charset=email_charset) except: # sending mail in Plone 3 mailhost.secureSend(message, email_recipient, source, subject=subject, subtype='plain', charset=email_charset, debug=False, From=source) return True
def __call__(self): ''' Does send the mail ''' mailhost = self.get_mailhost() source = self.get_from() recipients = self.get_recipients() subject = self.expand_markers(self.element.subject) message = self.expand_markers(self.element.message) email_charset = self.portal.getProperty('email_charset') for email_recipient in recipients: logger.debug('sending to: %s' % email_recipient) try: # sending mail in Plone 4 mailhost.send(message, mto=email_recipient, mfrom=source, subject=subject, charset=email_charset) except: # sending mail in Plone 3 mailhost.secureSend(message, email_recipient, source, subject=subject, subtype='plain', charset=email_charset, debug=False, From=source) return True
def get_recipients(self): ''' The recipients of this mail ''' # Try to load data from the target object fieldName = str(self.element.fieldName) obj = self.get_target_obj() # 1: object attribute try: # BBB don't have time to investigate difference between original __getattribute__ # and this getattr... _getattribute__ remove the possibility to use objects chain attr = getattr(obj, fieldName) # 3: object method if hasattr(attr, '__call__'): recipients = attr() logger.debug('getting e-mail from %s method' % fieldName) else: recipients = attr logger.debug('getting e-mail from %s attribute' % fieldName) except AttributeError: # 2: try with AT field if IBaseContent.providedBy(obj): field = obj.getField(fieldName) if field: recipients = field.get(obj) else: recipients = False else: recipients = False if not recipients: recipients = obj.getProperty(fieldName, []) if recipients: logger.debug('getting e-mail from %s CMF property' % fieldName) else: logger.debug('getting e-mail from %s AT field' % fieldName) # now transform recipients in a iterator, if needed if type(recipients) == str or type(recipients) == unicode: recipients = [ str(recipients), ] return filter(bool, recipients)
def get_recipients(self): ''' The recipients of this mail ''' # Try to load data from the target object fieldName = str(self.element.fieldName) obj = self.get_target_obj() # 1: object attribute try: # BBB don't have time to investigate difference between original __getattribute__ # and this getattr... _getattribute__ remove the possibility to use objects chain attr = getattr(obj, fieldName) # 3: object method if hasattr(attr, '__call__'): recipients = attr() logger.debug('getting e-mail from %s method' % fieldName) else: recipients = attr logger.debug('getting e-mail from %s attribute' % fieldName) except AttributeError: # 2: try with AT field if IBaseContent.providedBy(obj): field = obj.getField(fieldName) if field: recipients = field.get(obj) else: recipients = False else: recipients = False if not recipients: recipients = obj.getProperty(fieldName, []) if recipients: logger.debug('getting e-mail from %s CMF property' % fieldName) else: logger.debug('getting e-mail from %s AT field' % fieldName) # now transform recipients in a iterator, if needed if type(recipients) == str or type(recipients) == unicode: recipients = [str(recipients), ] return filter(bool, recipients)