本文整理匯總了Python中django.core.mail.mail_admins方法的典型用法代碼示例。如果您正苦於以下問題:Python mail.mail_admins方法的具體用法?Python mail.mail_admins怎麽用?Python mail.mail_admins使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.core.mail
的用法示例。
在下文中一共展示了mail.mail_admins方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_admin_settings
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import mail_admins [as 別名]
def test_admin_settings(self):
"""Verify that we configure email with environment variable"""
with mock.patch.dict('os.environ', {
**REQUIRED_SETTINGS,
'MICROMASTERS_ADMIN_EMAIL': ''
}, clear=True):
settings_vars = self.reload_settings()
self.assertFalse(settings_vars.get('ADMINS', False))
test_admin_email = 'cuddle_bunnies@example.com'
with mock.patch.dict('os.environ', {
**REQUIRED_SETTINGS,
'MICROMASTERS_ADMIN_EMAIL': test_admin_email,
}, clear=True):
settings_vars = self.reload_settings()
self.assertEqual(
(('Admins', test_admin_email),),
settings_vars['ADMINS']
)
# Manually set ADMIN to our test setting and verify e-mail
# goes where we expect
settings.ADMINS = (('Admins', test_admin_email),)
mail.mail_admins('Test', 'message')
self.assertIn(test_admin_email, mail.outbox[0].to)
示例2: send_mail
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import mail_admins [as 別名]
def send_mail(self, subject, message, *args, **kwargs):
mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs)
示例3: emit
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import mail_admins [as 別名]
def emit(self, record):
try:
request = record.request
subject = '%s (%s IP): %s' % (
record.levelname,
(request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS
and 'internal' or 'EXTERNAL'),
record.getMessage()
)
filter = get_exception_reporter_filter(request)
request_repr = filter.get_request_repr(request)
except Exception:
subject = '%s: %s' % (
record.levelname,
record.getMessage()
)
request = None
request_repr = "Request repr() unavailable."
subject = self.format_subject(subject)
if record.exc_info:
exc_info = record.exc_info
stack_trace = '\n'.join(traceback.format_exception(*record.exc_info))
else:
exc_info = (None, record.getMessage(), None)
stack_trace = 'No stack trace available'
message = "%s\n\n%s" % (stack_trace, request_repr)
reporter = ExceptionReporter(request, is_email=True, *exc_info)
html_message = self.include_html and reporter.get_traceback_html() or None
mail.mail_admins(subject, message, fail_silently=True, html_message=html_message)
示例4: test_uses_custom_email_backend
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import mail_admins [as 別名]
def test_uses_custom_email_backend(self):
"""
Refs #19325
"""
message = 'All work and no play makes Jack a dull boy'
admin_email_handler = self.get_admin_email_handler(self.logger)
mail_admins_called = {'called': False}
def my_mail_admins(*args, **kwargs):
connection = kwargs['connection']
self.assertIsInstance(connection, MyEmailBackend)
mail_admins_called['called'] = True
# Monkeypatches
orig_mail_admins = mail.mail_admins
orig_email_backend = admin_email_handler.email_backend
mail.mail_admins = my_mail_admins
admin_email_handler.email_backend = (
'logging_tests.logconfig.MyEmailBackend')
try:
self.logger.error(message)
self.assertTrue(mail_admins_called['called'])
finally:
# Revert Monkeypatches
mail.mail_admins = orig_mail_admins
admin_email_handler.email_backend = orig_email_backend