當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。