当前位置: 首页>>代码示例>>Python>>正文


Python Mailer.stop方法代码示例

本文整理汇总了Python中marrow.mailer.Mailer.stop方法的典型用法代码示例。如果您正苦于以下问题:Python Mailer.stop方法的具体用法?Python Mailer.stop怎么用?Python Mailer.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在marrow.mailer.Mailer的用法示例。


在下文中一共展示了Mailer.stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_send

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import stop [as 别名]
 def test_send(self):
     message = Bunch(id='foo')
     
     interface = Mailer(base_config)
     
     self.assertRaises(MailerNotRunning, interface.send, message)
     
     interface.start()
     
     logging.getLogger().handlers[0].truncate()
     messages = logging.getLogger().handlers[0].buffer
     
     self.assertEqual(interface.send(message), (message, True))
     
     self.assertEqual(messages[0].getMessage(), "Attempting delivery of message foo.")
     self.assertEqual(messages[-1].getMessage(), "Message foo delivered.")
     
     message_fail = Bunch(id='bar', die=True)
     self.assertRaises(Exception, interface.send, message_fail)
     
     self.assertEqual(messages[-4].getMessage(), "Attempting delivery of message bar.")
     self.assertEqual(messages[-3].getMessage(), "Acquired existing transport instance.")
     self.assertEqual(messages[-2].getMessage(), "Shutting down transport due to unhandled exception.")
     self.assertEqual(messages[-1].getMessage(), "Delivery of message bar failed.")
     
     interface.stop()
开发者ID:DatatracCorporation,项目名称:marrow.mailer,代码行数:28,代码来源:test_core.py

示例2: send_email

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import stop [as 别名]
def send_email(send_to, templaterich, templateplain, subject, **kwargs):
    """
        Sends an email to the target email with two types
            1) HTML
            2) Plain

        We will try the template with .htm for rich and .txt for plain.

        Both will rendered with Jinja2
    """

    mailer = Mailer(dict(
        transport=dict(use='smtp', host=config.EMAIL_SMTP_SERVER, debug=config.EMAIL_DEBUG),
        manager=dict()))

    mailer.start()

    message = mailer.new()
    message.author = config.EMAIL_SENDER
    message.to = send_to
    message.subject = subject

    template_rich = env.get_template(templaterich)
    template_plain = env.get_template(templateplain)

    message.rich = template_rich.render(**kwargs)
    message.plain = template_plain.render(**kwargs)

    logger.info('Sent an email to ' + send_to)

    message.send()
    mailer.stop()
开发者ID:haukurk,项目名称:earthquake-notifier,代码行数:34,代码来源:listener.py

示例3: send_mail_via_smtp_

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import stop [as 别名]
    def send_mail_via_smtp_(config, payload):
        """
        Send email via SMTP
        :param config:
        :param payload:
        :return:
        """
        mailer_config = {
            'transport': {
                'use': 'smtp',
                'host': config['host'],
                'username': config['username'],
                'password': config['password'],
                'tls': config['encryption'],
                'port': config['port']
            }
        }

        mailer = Mailer(mailer_config)
        mailer.start()
        message = Message(author=payload['from'], to=payload['to'])
        message.subject = payload['subject']
        message.plain = strip_tags(payload['html'])
        message.rich = payload['html']
        mailer.send(message)
        mailer.stop()
开发者ID:PareshMayani,项目名称:open-event-android,代码行数:28,代码来源:notification.py

示例4: test_send

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import stop [as 别名]
    def test_send(self):
        message = Bunch(id="foo")

        interface = Mailer(base_config)

        with pytest.raises(MailerNotRunning):
            interface.send(message)

        interface.start()

        # logging.getLogger().handlers[0].truncate()
        # messages = logging.getLogger().handlers[0].buffer

        assert interface.send(message) == (message, True)

        # assert messages[0] == "Attempting delivery of message foo."
        # assert messages[-1] == "Message foo delivered."

        message_fail = Bunch(id="bar", die=True)

        with pytest.raises(Exception):
            interface.send(message_fail)

            # assert messages[-4] == "Attempting delivery of message bar."
            # assert messages[-3] == "Acquired existing transport instance."
            # assert messages[-2] == "Shutting down transport due to unhandled exception."
            # assert messages[-1] == "Delivery of message bar failed."

        interface.stop()
开发者ID:nandoflorestan,项目名称:marrow.mailer,代码行数:31,代码来源:test_core.py

示例5: test_issue_2

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import stop [as 别名]
def test_issue_2():
    mail = Mailer({
            'manager.use': 'immediate',
            'transport.use': 'smtp',
            'transport.host': 'secure.emailsrvr.com',
            'transport.tls': 'ssl'
        })
    
    mail.start()
    mail.stop()
开发者ID:cynepiaadmin,项目名称:mailer,代码行数:12,代码来源:test_issue_2.py

示例6: test_shutdown

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import stop [as 别名]
    def test_shutdown(self):
        interface = Mailer(base_config)
        interface.start()

        # logging.getLogger().handlers[0].truncate()
        # messages = logging.getLogger().handlers[0].buffer

        interface.stop()

        # assert len(messages) == 5
        # assert messages[0] == "Mail delivery service stopping."
        # assert messages[-1] == "Mail delivery service stopped."

        interface.stop()
开发者ID:nandoflorestan,项目名称:marrow.mailer,代码行数:16,代码来源:test_core.py

示例7: SendEmail

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import stop [as 别名]
class SendEmail(object):
    def __init__(self, username="", password="", use="smtp", host="smtp.exmail.qq.com", port="25"):
        self.username = username
        self.mailer = Mailer(
            {
                "transport": {"use": use, "host": host, "port": port, "username": username, "password": password},
                "manager": {},
            }
        )

    def send_email(self, to, subject, content, author=""):
        self.mailer.start()
        self.mailer.send(Message(author=author or self.username, to=to, subject=subject, plain=content))
        self.mailer.stop()
开发者ID:Brightcells,项目名称:thingsforinternet,代码行数:16,代码来源:send_email.py

示例8: passwdreset

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import stop [as 别名]
 def passwdreset(self):
     """Render password reset page"""
     c.came_from = '/'
     c.login_counter = 0
     c.form = ResetPwForm(request.POST, csrf_context=session)
     if request.method == 'POST' and c.form.validate():
         key_seed = '%s%s' % (c.form.email.data, arrow.utcnow().ctime())
         token = hashlib.sha1(key_seed).hexdigest()
         user = Session.query(User)\
                         .filter(User.email == c.form.email.data)\
                         .one()
         if not user.local:
             flash(_('The account %s is an external account, use your'
                     ' External systems to change the password. '
                     'Contact your system adminstrator if you do not '
                     'know which external systems you authenticate to')
                     % user.email)
             redirect(url('/accounts/login'))
         rtoken = Session\
                 .query(ResetToken.used)\
                 .filter(ResetToken.used == false())\
                 .filter(ResetToken.user_id == user.id)\
                 .all()
         if not rtoken:
             rtoken = ResetToken(token, user.id)
             Session.add(rtoken)
             Session.commit()
             host = URL_PREFIX_RE.sub('', request.host_url)
             c.username = user.username
             c.firstname = user.firstname or user.username
             c.reset_url = url('accounts-pw-token-reset',
                             token=token,
                             host=host)
             text = self.render('/email/pwreset.txt')
             mailer = Mailer(get_conf_options(config))
             mailer.start()
             sdrnme = config.get('baruwa.custom.name', 'Baruwa')
             email = Msg(author=[(sdrnme,
                         config.get('baruwa.reports.sender'))],
                         to=[('', c.form.email.data)],
                         subject=_("[%s] Password reset request") % sdrnme)
             email.plain = text
             mailer.send(email)
             mailer.stop()
         flash(_('An email has been sent to the address provided, '
                 'please follow the instructions in that email to '
                 'reset your password.'))
         redirect(url('/accounts/login'))
     return self.render('/accounts/login.html')
开发者ID:baruwaproject,项目名称:baruwa2,代码行数:51,代码来源:accounts.py

示例9: test_startup

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import stop [as 别名]
 def test_startup(self):
     messages = logging.getLogger().handlers[0].buffer
     
     interface = Mailer(base_config)
     interface.start()
     
     self.assertEqual(len(messages), 5)
     self.assertEqual(messages[0].getMessage(), "Mail delivery service starting.")
     self.assertEqual(messages[-1].getMessage(), "Mail delivery service started.")
     
     interface.start()
     
     self.assertEqual(len(messages), 6)
     self.assertEqual(messages[-1].getMessage(), "Attempt made to start an already running Mailer service.")
     
     interface.stop()
开发者ID:DatatracCorporation,项目名称:marrow.mailer,代码行数:18,代码来源:test_core.py

示例10: test_startup

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import stop [as 别名]
    def test_startup(self):
        # messages = logging.getLogger().handlers[0].buffer

        interface = Mailer(base_config)
        interface.start()

        # assert len(messages) == 5
        # assert messages[0] == "Mail delivery service starting."
        # assert messages[-1] == "Mail delivery service started."

        interface.start()

        # assert len(messages) == 6
        # assert messages[-1] == "Attempt made to start an already running Mailer service."

        interface.stop()
开发者ID:nandoflorestan,项目名称:marrow.mailer,代码行数:18,代码来源:test_core.py

示例11: includeme

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import stop [as 别名]
def includeme(config):
    """Configure marrow.mailer"""
    settings = config.registry.settings
    prefix = settings.get('pyramid_marrowmailer.prefix', 'mail.').rstrip('.')

    # handle boolean options and int options .digit .on
    mailer_config = dict(filter(lambda d: d[0].startswith(prefix),
                                settings.items()))
    for key, value in dict(mailer_config).items():
        if key.endswith('.on'):
            mailer_config[key[:-3]] = asbool(value)
        if key.endswith('.int'):
            mailer_config[key[:-4]] = int(value)

    # bugfix for https://github.com/marrow/marrow.mailer/issues/45
    manager = '%s.manager.use' % prefix
    if manager not in mailer_config:
        mailer_config[manager] = 'immediate'

    mode = '%s.mode' % prefix
    if mailer_config.get(mode) == 'direct':
        mailer = Mailer(mailer_config, prefix)
    else:
        mailer = TransactionMailer(mailer_config, prefix)

    mailer.start()

    config.registry.registerUtility(mailer, IMarrowMailer)
    config.set_request_property(get_mailer, "mailer", reify=True)

    # shutdown mailer when process stops
    atexit.register(lambda: mailer.stop())
开发者ID:kralla,项目名称:pyramid_marrowmailer,代码行数:34,代码来源:__init__.py

示例12: test_shutdown

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import stop [as 别名]
 def test_shutdown(self):
     interface = Mailer(base_config)
     interface.start()
     
     logging.getLogger().handlers[0].truncate()
     messages = logging.getLogger().handlers[0].buffer
     
     interface.stop()
     
     self.assertEqual(len(messages), 5)
     self.assertEqual(messages[0].getMessage(), "Mail delivery service stopping.")
     self.assertEqual(messages[-1].getMessage(), "Mail delivery service stopped.")
     
     interface.stop()
     
     self.assertEqual(len(messages), 6)
     self.assertEqual(messages[-1].getMessage(), "Attempt made to stop an already stopped Mailer service.")
开发者ID:DatatracCorporation,项目名称:marrow.mailer,代码行数:19,代码来源:test_core.py

示例13: send_spam_alert

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import stop [as 别名]
def send_spam_alert(number, calls_today, calls_per_minute, concurrent_calls):
    if not config.getboolean('email', 'enabled'):
        return

    mailer = Mailer({'transport.use': 'sendmail'})

    message = Message(author=config.get('mail', 'from'),
                      to=config.get('mail', 'to'))
    message.subject = config.get('mail', 'subject')
    message.plain = EMAIL_MESSAGE.format(number=number,
                                         calls_today=calls_today,
                                         calls_per_minute=calls_per_minute,
                                         concurrent_calls=concurrent_calls)

    mailer.start()
    mailer.send(message)
    mailer.stop()
开发者ID:gelendir,项目名称:becky,代码行数:19,代码来源:call_limit.py

示例14: command

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import stop [as 别名]
    def command(self):
        "command"
        self.init()
        if self.options.email is None:
            print "\nA valid email is required\n"
            print self.parser.print_help()
            sys.exit(2)

        starttime = arrow.utcnow().datetime

        if self.options.report_period == 'daily':
            endtime = starttime - datetime.timedelta(days=1)
        elif self.options.report_period == 'weekly':
            endtime = starttime - datetime.timedelta(weeks=1)
        else:
            endtime = starttime - datetime.timedelta(weeks=4)

        params = dict(spamscore=self.options.spamscore, num=self.options.num,
                    starttime=starttime, endtime=endtime)

        sql = text("""SELECT clientip, COUNT(clientip) a
                    FROM messages WHERE sascore >= :spamscore
                    AND (timestamp BETWEEN :endtime AND :starttime)
                    GROUP BY clientip HAVING COUNT(clientip) >= :num
                    ORDER BY a DESC;""")
        results = Session.execute(sql, params=params)
        if results.rowcount:
            if self.options.include_count is False:
                records = [result.clientip for result in results]
            else:
                records = ["%s\t%d" % tuple(result) for result in results]
            content = "\n".join(records)
            if self.options.dry_run is True:
                print content
            else:
                mailer = Mailer(get_conf_options(self.conf))
                mailer.start()
                email = Msg(author=self.conf['baruwa.reports.sender'],
                            to=self.options.email, subject='TSL')
                email.plain = content
                try:
                    mailer.send(email)
                except (TransportFailedException, MessageFailedException), err:
                    print >> sys.stderr, err
                mailer.stop()
开发者ID:baruwaproject,项目名称:baruwa2,代码行数:47,代码来源:topspammers.py

示例15: Mailer

# 需要导入模块: from marrow.mailer import Mailer [as 别名]
# 或者: from marrow.mailer.Mailer import stop [as 别名]
class Mailer(object):
    def __init__(self):
        self.config = Config().config['mail']
        self.mailer = MarrowMailer(
            dict(
                transport=dict(debug=True,
                               **self.config),
                manager=dict(),
                ),
            )

    def send(self, message):
        self.mailer.start()
        self.mailer.send(message)
        self.mailer.stop()
        pass

    def send_activation_message_to_mentor(self, mentor):
        message = ActivationMessage(mentor, Config().config['secret_key'])
        self.send(message)
开发者ID:ncgaskin,项目名称:mentor-finder,代码行数:22,代码来源:mailers.py


注:本文中的marrow.mailer.Mailer.stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。