def send_email(sender=None, recipient=None, subject=None, body=None): """Send an email. :param sender: Email sender, 'from' field. If not set, the portal default will be used. :type sender: string :param recipient: [required] Email recipient, 'to' field. :type recipient: string :param subject: [required] Subject of the email. :type subject: string :param body: [required] Body text of the email :type body: string :raises: ValueError :Example: :ref:`portal_send_email_example` """ portal = get() if not PRINTINGMAILHOST_ENABLED: from plone.api import content ctrlOverview = content.get_view( context=portal, request=portal.REQUEST, name='overview-controlpanel', ) if ctrlOverview.mailhost_warning(): raise ValueError('MailHost is not configured.') try: encoding = get_registry_record('plone.email_charset') except InvalidParameterError: encoding = portal.getProperty('email_charset', 'utf-8') if not sender: try: from_address = get_registry_record('plone.email_from_address') from_name = get_registry_record('plone.email_from_name') except InvalidParameterError: # Before Plone 5.0b2 these were stored in portal_properties from_address = portal.getProperty('email_from_address', '') from_name = portal.getProperty('email_from_name', '') sender = formataddr((from_name, from_address)) if parseaddr(sender)[1] != from_address: # formataddr probably got confused by special characters. sender = from_address # If the mail headers are not properly encoded we need to extract # them and let MailHost manage the encoding. if isinstance(body, unicode): body = body.encode(encoding) host = get_tool('MailHost') host.send(body, recipient, sender, subject=subject, charset=encoding, immediate=True)
def send_email(sender=None, recipient=None, subject=None, body=None): """Send an email. :param sender: Email sender, 'from' field. If not set, the portal default will be used. :type sender: string :param recipient: [required] Email recipient, 'to' field. :type recipient: string :param subject: [required] Subject of the email. :type subject: string :param body: [required] Body text of the email :type body: string :raises: ValueError :Example: :ref:`portal_send_email_example` """ portal = get() if not PRINTINGMAILHOST_ENABLED: from plone.api import content ctrlOverview = content.get_view( context=portal, request=portal.REQUEST, name='overview-controlpanel', ) if ctrlOverview.mailhost_warning(): raise ValueError('MailHost is not configured.') encoding = portal.getProperty('email_charset', 'utf-8') if not sender: try: from_address = get_registry_record('plone.email_from_address') from_name = get_registry_record('plone.email_from_name') except InvalidParameterError: # Before Plone 5.0b2 these were stored in portal_properties from_address = portal.getProperty('email_from_address', '') from_name = portal.getProperty('email_from_name', '') sender = formataddr((from_name, from_address)) if parseaddr(sender)[1] != from_address: # formataddr probably got confused by special characters. sender = from_address # If the mail headers are not properly encoded we need to extract # them and let MailHost manage the encoding. if isinstance(body, unicode): body = body.encode(encoding) host = get_tool('MailHost') host.send( body, recipient, sender, subject=subject, charset=encoding, immediate=True )
def _sponsors(self): catalog = get_tool('portal_catalog') brains = catalog(portal_type='sponsor') results = [] for brain in brains: obj = brain.getObject() scales = get_view(name='images', context=obj, request=self.request) scale = scales.scale('logo', width=200, height=80, direction='down') tag = scale.tag() if scale else '' if not tag: # only display sponsors with a logo continue results.append(dict( title=brain.Title, description=brain.Description, tag=tag, url=obj.url or obj.absolute_url(), level=obj.level )) return results
def _sponsors(self): catalog = get_tool('portal_catalog') brains = catalog(portal_type='sponsor') results = [] for brain in brains: obj = brain.getObject() scales = get_view(name='images', context=obj, request=self.request) scale = scales.scale('logo', width=200, height=80, direction='down') tag = scale.tag() if scale else '' if not tag: # only display sponsors with a logo continue results.append( dict(title=brain.Title, description=brain.Description, tag=tag, url=obj.url or obj.absolute_url(), level=obj.level)) return results