本文整理汇总了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()