Beispiel #1
0
    def __init__(self):
        '''
        :ivar to_addr: The default recipient email address
            Will be set to the configuration variable "email_to",
            if configuration is available
        :ivar from_addr: The default sender email address
            Will be set to the configuration variable "admin_email_from",
            if configuration is available
        '''

        self.to_addr = config.get('email_to')
        self.from_addr = config.get('admin_email_from')

        smtp_server = config.get('smtp_server')
        smtp_use_tls = asbool(config.get('smtp_use_tls'))
        smtp_username = config.get('smtp_username')
        smtp_password = config.get('smtp_password')

        test = asbool(config.get('test'))

        if test:
            log.debug('Using DummyDelivery()')
            self.delivery = DummyDelivery()
        else:  # pragma: no cover
            if smtp_server:
                mailer = SMTPMailer(hostname=smtp_server,
                                    username=smtp_username,
                                    password=smtp_password,
                                    force_tls=smtp_use_tls)
                log.debug('Using SMTPMailer(hostname=%s, ...)', smtp_server)
            else:
                mailer = SendmailMailer()
                log.debug('Using SendmailMailer()')
            self.delivery = DirectMailDelivery(mailer)
Beispiel #2
0
    def __init__(self,
                 host='localhost',
                 port=25,
                 username=None,
                 password=None,
                 tls=False,
                 ssl=False,
                 keyfile=None,
                 certfile=None,
                 queue_path=None,
                 default_sender=None,
                 sendmail_app=None,
                 sendmail_template=None,
                 debug=0):
        if ssl:
            self.smtp_mailer = SMTP_SSLMailer(
                hostname=host,
                port=port,
                username=username,
                password=password,
                no_tls=not(tls),
                force_tls=tls,
                debug_smtp=debug,
                keyfile=keyfile,
                certfile=certfile)
        else:
            self.smtp_mailer = SMTPMailer(
                hostname=host,
                port=port,
                username=username,
                password=password,
                no_tls=not(tls),
                force_tls=tls,
                debug_smtp=debug)

        self.direct_delivery = DirectMailDelivery(self.smtp_mailer)

        if queue_path:
            self.queue_delivery = QueuedMailDelivery(queue_path)
        else:
            self.queue_delivery = None

        self.sendmail_mailer = SendmailMailer(sendmail_app, sendmail_template)
        self.sendmail_delivery = DirectMailDelivery(self.sendmail_mailer)
        self.default_sender = default_sender
Beispiel #3
0
    def __init__(self, **kw):
        smtp_mailer = kw.pop('smtp_mailer', None)
        if smtp_mailer is None:
            host = kw.pop('host', 'localhost')
            port = kw.pop('port', 25)
            username = kw.pop('username', None)
            password = kw.pop('password', None)
            tls = kw.pop('tls', False)
            ssl = kw.pop('ssl', False)
            keyfile = kw.pop('keyfile', None)
            certfile = kw.pop('certfile', None)
            debug = kw.pop('debug', 0)
            if ssl:
                smtp_mailer = SMTP_SSLMailer(hostname=host,
                                             port=port,
                                             username=username,
                                             password=password,
                                             no_tls=not (tls),
                                             force_tls=tls,
                                             debug_smtp=debug,
                                             keyfile=keyfile,
                                             certfile=certfile)
            else:
                smtp_mailer = SMTPMailer(hostname=host,
                                         port=port,
                                         username=username,
                                         password=password,
                                         no_tls=not (tls),
                                         force_tls=tls,
                                         debug_smtp=debug)
        self.smtp_mailer = smtp_mailer

        sendmail_mailer = kw.pop('sendmail_mailer', None)
        if sendmail_mailer is None:
            sendmail_mailer = SendmailMailer(
                kw.pop('sendmail_app', None),
                kw.pop('sendmail_template', None),
            )
        self.sendmail_mailer = sendmail_mailer

        self.queue_path = kw.pop('queue_path', None)
        self.default_sender = kw.pop('default_sender', None)

        transaction_manager = kw.pop('transaction_manager', None)
        if transaction_manager is None:
            transaction_manager = transaction.manager
        self.transaction_manager = transaction_manager

        if kw:
            raise ValueError('invalid options: %s' %
                             ', '.join(sorted(kw.keys())))

        self.direct_delivery = DirectMailDelivery(
            self.smtp_mailer, transaction_manager=transaction_manager)

        if self.queue_path:
            self.queue_delivery = QueuedMailDelivery(
                self.queue_path, transaction_manager=transaction_manager)
        else:
            self.queue_delivery = None

        self.sendmail_delivery = DirectMailDelivery(
            self.sendmail_mailer, transaction_manager=transaction_manager)