Esempio n. 1
0
 def handleApply(self, action):
     data, errors = self.extractData()
     if errors:
         self.status = self.formErrorsMessage
         return
     
     # Send mail
     mail_host = getToolByName(self, 'MailHost')
     try:
         msg = self.compose_mail(data['sender'], data['receiver'])
         mail_host.send(msg, immediate=True)
         msg = _(u'Message sent.')
         IStatusMessage(self.request).addStatusMessage(msg, type='info')
         self.request.RESPONSE.redirect(self.context.absolute_url())
     except SMTPException:
         msg = _('Error while sending email.')
         IStatusMessage(self.request).addStatusMessage(msg, type='error')
Esempio n. 2
0
 def compose_mail(self, sender, receiver):
     # Create PDF file
     assembler = getMultiAdapter((self.context, self.request), IPDFAssembler)
     pdf_file = assembler.build_pdf()
     
     # Compose mail
     msg = MIMEMultipart()
     msg['Subject'] = _('Book')
     msg['From'] = sender
     msg['To'] = receiver
     # Text block
     part = MIMEText(_('Book PDF attached'))
     msg.attach(part)
     # PDF attachement
     part = MIMEApplication(pdf_file)
     filename = '%s.pdf' % self.context.id
     part.add_header('Content-Disposition', 'attachment', filename=filename)
     msg.attach(part)
     return msg