當前位置: 首頁>>代碼示例>>Python>>正文


Python Mailer.new方法代碼示例

本文整理匯總了Python中marrow.mailer.Mailer.new方法的典型用法代碼示例。如果您正苦於以下問題:Python Mailer.new方法的具體用法?Python Mailer.new怎麽用?Python Mailer.new使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在marrow.mailer.Mailer的用法示例。


在下文中一共展示了Mailer.new方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_new

# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import new [as 別名]
    def test_new(self):
        config = dict(
            manager=dict(use="immediate"),
            transport=dict(use="mock"),
            message=dict(author="[email protected]", retries=1, brand=False),
        )

        interface = Mailer(config).start()
        message = interface.new(retries=2)

        assert message.author == ["[email protected]"]
        assert message.bcc == []
        assert message.retries == 2
        assert message.mailer is interface
        assert message.brand == False

        with pytest.raises(NotImplementedError):
            Message().send()

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

        message = interface.new("[email protected]", "[email protected]", "Test.")

        assert message.author == ["[email protected]"]
        assert message.to == ["[email protected]"]
        assert message.subject == "Test."
開發者ID:nandoflorestan,項目名稱:marrow.mailer,代碼行數:28,代碼來源:test_core.py

示例2: send_email

# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import new [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: MailHandler

# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import new [as 別名]
class MailHandler(logging.Handler):
    """A class which sends records out via e-mail.
    
    This handler should be configured using the same configuration
    directives that Marrow Mailer itself understands.
    
    Be careful how many notifications get sent.
    
    It is suggested to use background delivery using the 'dynamic' manager.
    """
    
    def __init__(self, *args, **config):
        """Initialize the instance, optionally configuring TurboMail itself.
        
        If no additional arguments are supplied to the handler, re-use any
        existing running TurboMail configuration.
        
        To get around limitations of the INI parser, you can pass in a tuple
        of name, value pairs to populate the dictionary.  (Use `{}` dict
        notation in produciton, though.)
        """
        
        logging.Handler.__init__(self)
        
        self.config = dict()
        
        if args:
            config.update(dict(zip(*[iter(args)]*2)))
        
        self.mailer = Mailer(config).start()
        
        # If we get a configuration that doesn't explicitly start TurboMail
        # we use the configuration to populate the Message instance.
        self.config = config
    
    def emit(self, record):
        """Emit a record."""
        
        try:
            self.mailer.new(plain=self.format(record)).send()
        
        except (KeyboardInterrupt, SystemExit):
            raise
        
        except:
            self.handleError(record)
開發者ID:DatatracCorporation,項目名稱:marrow.mailer,代碼行數:48,代碼來源:logger.py

示例4: test_new

# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import new [as 別名]
 def test_new(self):
     config = dict(manager=dict(use='immediate'), transport=dict(use='mock'),
             message=dict(author='[email protected]', retries=1, brand=False))
     
     interface = Mailer(config).start()
     message = interface.new(retries=2)
     
     self.assertEqual(message.author, ["[email protected]"])
     self.assertEqual(message.bcc, [])
     self.assertEqual(message.retries, 2)
     self.assertTrue(message.mailer is interface)
     self.assertEqual(message.brand, False)
     
     self.assertRaises(NotImplementedError, Message().send)
     
     self.assertEqual(message.send(), (message, True))
     
     message = interface.new("[email protected]", "[email protected]", "Test.")
     
     self.assertEqual(message.author, ["[email protected]"])
     self.assertEqual(message.to, ["[email protected]"])
     self.assertEqual(message.subject, "Test.")
開發者ID:DatatracCorporation,項目名稱:marrow.mailer,代碼行數:24,代碼來源:test_core.py

示例5: send_mail

# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import new [as 別名]
def send_mail(subject, plain, html):
  """This function assumes that email is HTML formatted"""
  mailer = Mailer(dict( transport = dict(
    use = 'smtp',
    debug = config.EMAIL_DEBUG,
    host = config.EMAIL_HOST,
    port = config.EMAIL_PORT,
    username = config.EMAIL_FROM,
    password = config.EMAIL_PASS,
    tls = config.EMAIL_SSL),
    manager = dict())
  )

  mailer.start()
  message = mailer.new()
  message.subject = subject
  message.author = config.EMAIL_FROM
  message.to = config.EMAIL_TO
  message.plain = plain
  message.rich = html
  mailer.send(message)
  mailer.stop()
開發者ID:sarlalian,項目名稱:watchmen,代碼行數:24,代碼來源:mailer.py


注:本文中的marrow.mailer.Mailer.new方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。