Пример #1
0
 def _send(self, mfrom, mto, messageText, debug=False):
     """Send the message
     """
     if not isinstance(messageText, email.Message.Message):
         message = email.message_from_string(messageText)
     else:
         message = messageText
     smtp_notls = getattr(self, 'smtp_notls', False)
     mail = Mail(mfrom, mto, message, smtp_host=self.smtp_host,
                 smtp_port=self.smtp_port, userid=self._smtp_userid,
                 password=self._smtp_pass, notls=smtp_notls
                )
     if debug:
         return mail
     else:
         mail.send()
Пример #2
0
 def _send(self, mfrom, mto, messageText, debug=False):
     """Send the message
     """
     if not isinstance(messageText, email.Message.Message):
         message = email.message_from_string(messageText)
     else:
         message = messageText
     smtp_notls = getattr(self, "smtp_notls", False)
     mail = Mail(
         mfrom,
         mto,
         message,
         smtp_host=self.smtp_host,
         smtp_port=self.smtp_port,
         userid=self._smtp_userid,
         password=self._smtp_pass,
         notls=smtp_notls,
     )
     if debug:
         return mail
     else:
         mail.send()
    def _send(self, mfrom, mto, messageText, debug=False):
        """Send the message
        """
        if debug:
            if not isinstance(messageText, email.Message.Message):
                message = email.message_from_string(messageText)
            else:
                message = messageText
            return Mail(mfrom,
                        mto,
                        message,
                        smtp_host=self.smtp_host,
                        smtp_port=self.smtp_port,
                        userid=self.smtp_uid,
                        password=self.smtp_pwd,
                        notls=self.smtp_notls)

        if isinstance(messageText, email.Message.Message):
            messageText = messageText.as_string()
        MailBase._send(self, mfrom, mto, messageText)
    def send(self): 
        """ Send Invoice to recipients
        """
        invoice = self.invoice
        root = invoice.getAccountingRoot()
        portal = getToolByName(invoice, 'portal_url').getPortalObject()
        host = portal.MailHost
        template = getattr(portal, 'invoice_mail_template')
        encoding = portal.getProperty('email_charset')
        send_from_address = formataddr(
            ( root.getOrganisationName(), root.getEmail() )
        )

        # Compile a list of contacts for the customer
        customer = invoice.getCustomerAccount()
        to_addrs = []
        for contact in customer.getContacts():
            to_addrs.append(
                formataddr((contact.Title(), contact.getEmail()))
            )

        # if the customer doesn't have any contact, use the company
        # email address
        if not customer.getContacts():
            to_addrs.append(
                formataddr((customer.Title(), customer.getEmail()))
            )

        subject = '%s Invoice: %s' % (
            root.getOrganisationName(), invoice.getId())

        send_to_address = ', '.join(to_addrs)

        msg = MIMEMultipart('mixed')
        msg['Subject'] = subject
        msg['From'] = send_from_address
        msg['To'] = send_to_address

        # Generate message and attach to mail message
        message = template(OrganisationName=root.getOrganisationName())
        body = MIMEText(message, 'text', encoding)
        msg.attach(body)

        # Generate and attach PDF 
        invoice_pdf = invoice.invoice_pdf.getPDF(
            invoice.REQUEST, invoice.REQUEST.RESPONSE)
        pdf = MIMEBase('application', 'pdf')
        pdf.set_payload(invoice_pdf)

        # Encode the payload using Base64
        Encoders.encode_base64(pdf)

        # Set the filename parameter
        pdf.add_header('Content-Disposition', 'attachment',
            filename='%s.pdf' % invoice.getId())
        msg.attach(pdf)

        # We are not using SecureMailHost.secureSend because it cannot
        # handle a multipart message
        mail = Mail(send_from_address, send_to_address, msg,
            smtp_host=host.smtp_host, smtp_port=host.smtp_port,
            userid=host._smtp_userid, password=host._smtp_pass)
        mail.send()

        # Send the message to ourselves
        mail = Mail(send_from_address, send_from_address, msg,
            smtp_host=host.smtp_host, smtp_port=host.smtp_port,
            userid=host._smtp_userid, password=host._smtp_pass)
        mail.send()