def send(self):
     '''
     Send the email
     '''
     if not self.sla_patient:
         logger.info('Cannot send notification email: no patient found')
         return
     
     self.sendEmail(self._addresses, self._subject, self._text)
    def sendEmail(self, addresses, subject, rstText, cc = None):
        """
        Send a email to the list of addresses
        """
        portal_url  = getToolByName(self.context, 'portal_url')
        plone_utils = getToolByName(self.context, 'plone_utils')
    
        portal      = portal_url.getPortalObject()
        mailHost    = plone_utils.getMailHost()
        charset     = self.charset
        from_address = portal.getProperty('email_from_address', '')
    
        if not from_address:
            logger.info('Cannot send notification email: email sender address not set')
            return
        from_name = portal.getProperty('email_from_name', '')
        mfrom = formataddr((from_name, from_address))
        if parseaddr(mfrom)[1] != from_address:
            # formataddr probably got confused by special characters.
            mfrom - from_address

        # We must choose the body charset manually
        for body_charset in (charset, 'UTF-8', 'US-ASCII'):
            try:
                rstText = rstText.encode(body_charset)
            except UnicodeError:
                pass
            else:
                break
        
        email_msg = MIMEText(rstText, 'plain', body_charset)
    
        subject = safe_unicode(subject, charset)
    
        for address in addresses:
            address = safe_unicode(address, charset)
            if address:
                try:
                    # Note that charset is only used for the headers, not
                    # for the body text as that is a Message already.
                    mailHost.secureSend(message = email_msg,
                                        mto = address,
                                        mfrom = mfrom,
                                        subject = subject,
                                        charset = charset)
                except socket.error, exc:
                    log_exc(('Could not send email from %s to %s regarding issue '
                             'in content %s\ntext is:\n%s\n') % (
                            mfrom, address, self.context.absolute_url(), email_msg))
                    log_exc("Reason: %s: %r" % (exc.__class__.__name__, str(exc)))
                except:
                    raise
def create_form(patient):
    """
    Crea un form di defaul
    """
    form = _createEntry(patient, "FormFolder", '')
    title_adapter = _getTitleAdapter(form)
    adapter = _createEntry(form, "FormSaveData2ContentAdapter", title_adapter)
    adapter.setTitle(title_adapter)
    _configAdapter(adapter)
    adapter.reindexObject()
    _configForm(form, adapter)
    form.reindexObject()

    logger.info('Created form %s with adapter %s' % (form.id, adapter.id))
def send_alert(object, event):
    """
    Evento al cambio di stato del form
    """
    wtool = getToolByName(object, "portal_workflow")
    pc = getToolByName(object, "portal_catalog")
    wf_state = wtool.getInfoFor(object, 'review_state')
    parent = object.aq_parent
    same_state_forms = pc(path="/".join(parent.getPhysicalPath()),
                          portal_type=object.portal_type,
                          review_state=wf_state)
    if wf_state in ('red', 'yellow', 'green') and not same_state_forms:
        dc_notification = getAdapter(object, IPercorsoSLAMail, name="notify_doctor")
        dc_notification.send()
        logger.info('Notification to doctors sent')
def to_1100(context):
    """
    """
    logger.info('Upgrading ospfe.percorso_sla to version 0.4')
    context.runAllImportStepsFromProfile(default_profile)
    logger.info('End of upgrade step')