Example #1
0
    def send(self, fromaddr=None, toaddrs=None, message=None):
        if not isinstance(message, Message):
            raise ValueError(
               'Message must be instance of email.message.Message')
        message = encode_message(message)
        if toaddrs is None:
            toaddrs = []

        args = [arg.format(sendmail_app=self.sendmail_app,
                           sender=fromaddr,
                           recipients=toaddrs)
                for arg in self.sendmail_template] + list(toaddrs)
        p = self._popen(args)
        stdoutdata, stderrdata = p.communicate(message)
        if p.returncode:
            raise subprocess.CalledProcessError(
                "Could not excecute sendmail properly", args)
    def send(self, fromaddr=None, toaddrs=None, message=None):
        if not isinstance(message, Message):
            raise ValueError(
                'Message must be instance of email.message.Message')
        message = encode_message(message)
        if toaddrs is None:
            toaddrs = []

        args = [
            arg.format(sendmail_app=self.sendmail_app,
                       sender=fromaddr,
                       recipients=toaddrs) for arg in self.sendmail_template
        ] + list(toaddrs)
        p = self._popen(args)
        stdoutdata, stderrdata = p.communicate(message)
        if p.returncode:
            raise subprocess.CalledProcessError(
                "Could not excecute sendmail properly", args)
Example #3
0
    def send(self, fromaddr, toaddrs, message):
        if not isinstance(message, Message):
            raise ValueError(
               'Message must be instance of email.message.Message')
        message = encode_message(message)

        connection = self.smtp_factory()

        # send EHLO
        code, response = connection.ehlo()
        if code < 200 or code >= 300:
            code, response = connection.helo()
            if code < 200 or code >= 300:
                raise RuntimeError(
                        'Error sending HELO to the SMTP server '
                        '(code=%s, response=%s)' % (code, response))

        # encryption support
        have_tls = connection.has_extn('starttls')
        if not have_tls and self.force_tls:
            raise RuntimeError('TLS is not available but TLS is required')

        if have_tls and HAVE_SSL and not self.no_tls:
            connection.starttls()
            connection.ehlo()

        if connection.does_esmtp:
            if self.username is not None and self.password is not None:
                connection.login(self.username, self.password)
        elif self.username:
            raise RuntimeError(
                    'Mailhost does not support ESMTP but a username '
                    'is configured')

        connection.sendmail(fromaddr, toaddrs, message)
        try:
            connection.quit()
        except SSLError:
            # something weird happened while quiting
            connection.close()
    def send(self, fromaddr, toaddrs, message):
        if not isinstance(message, Message):
            raise ValueError(
                'Message must be instance of email.message.Message')
        message = encode_message(message)

        connection = self.smtp_factory()

        # send EHLO
        code, response = connection.ehlo()
        if code < 200 or code >= 300:
            code, response = connection.helo()
            if code < 200 or code >= 300:
                raise RuntimeError('Error sending HELO to the SMTP server '
                                   '(code=%s, response=%s)' % (code, response))

        # encryption support
        have_tls = connection.has_extn('starttls')
        if not have_tls and self.force_tls:
            raise RuntimeError('TLS is not available but TLS is required')

        if have_tls and HAVE_SSL and not self.no_tls:
            connection.starttls()
            connection.ehlo()

        if connection.does_esmtp:
            if self.username is not None and self.password is not None:
                connection.login(self.username, self.password)
        elif self.username:
            raise RuntimeError(
                'Mailhost does not support ESMTP but a username '
                'is configured')

        connection.sendmail(fromaddr, toaddrs, message)
        try:
            connection.quit()
        except SSLError:
            # something weird happened while quiting
            connection.close()
 def _callFUT(self, message):
     from repoze.sendmail.encoding import encode_message
     return encode_message(message)
 def _callFUT(self, message):
     from repoze.sendmail.encoding import encode_message
     return encode_message(message)
Example #7
0
 def encode(self, message=None):
     if message is None:
         message = self.message
     from repoze.sendmail import encoding
     return encoding.encode_message(message)