本文整理匯總了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."
示例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()
示例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)
示例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.")
示例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()