本文整理匯總了Python中marrow.mailer.Mailer.start方法的典型用法代碼示例。如果您正苦於以下問題:Python Mailer.start方法的具體用法?Python Mailer.start怎麽用?Python Mailer.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類marrow.mailer.Mailer
的用法示例。
在下文中一共展示了Mailer.start方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: send_email
# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import start [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()
示例2: includeme
# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import start [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())
示例3: test_send
# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import start [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()
示例4: test_send
# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import start [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()
示例5: send_mail_via_smtp_
# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import start [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()
示例6: _get_mailer
# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import start [as 別名]
def _get_mailer(request):
global _mailer, _last_change
if _mailer:
if _last_change != request.config['_last_change']:
mailer = _mailer
_mailer = None
stop_mailer(mailer)
if not _mailer:
transport = {
'use': 'smtp',
'host': os.environ.get('CIOC_MAIL_HOST', '127.0.0.1'),
'username': os.environ.get('CIOC_MAIL_USERNAME'),
'password': os.environ.get('CIOC_MAIL_PASSWORD'),
'port': os.environ.get('CIOC_MAIL_PORT'),
'tls': 'ssl' if os.environ.get('CIOC_MAIL_USE_SSL') else None,
}
# print transport['host']
transport = {k: v for k, v in transport.iteritems() if v}
_mailer = Mailer({
'transport': transport,
'manager': {'use': request.config.get('mailer.manager', 'immediate')}
})
_mailer.start()
return _mailer
示例7: test_issue_2
# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import start [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()
示例8: SendEmail
# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import start [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()
示例9: test_shutdown
# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import start [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()
示例10: passwdreset
# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import start [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')
示例11: test_startup
# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import start [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()
示例12: test_startup
# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import start [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()
示例13: send_spam_alert
# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import start [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()
示例14: MailingAdapter
# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import start [as 別名]
class MailingAdapter(object):
def __init__(self, host, port):
self.mailer = Mailer(dict(
manager = dict(
use = 'immediate'),
transport = dict(
use = 'smtp',
port = port,
host = host)))
self.mailer.start()
def send_mail(self, to_address, from_address, body):
message = Message(author=from_address, to=to_address)
message.subject = "Testing Marrow Mailer"
message.plain = body
self.mailer.send(message)
示例15: test_shutdown
# 需要導入模塊: from marrow.mailer import Mailer [as 別名]
# 或者: from marrow.mailer.Mailer import start [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.")