08.配置django发送log邮件

https://docs.djangoproject.com/en/3.0/topics/email/https://docs.djangoproject.com/en/3.0/topics/email/#topic-email-backends
sentry 不香么

一.网上的

https://www.sohu.com/a/193738029_236714

  • settings - hannder
'mail_admin': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
            'include_html': tRUE,
        },
  • settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'mail.xxxx.com.cn'  # SMTP地址
EMAIL_PORT = 25  # SMTP端口
EMAIL_HOST_USER = 'xxxx@xxxx.com.cn'  # 发送邮件的【邮箱账户】
EMAIL_HOST_PASSWORD = 'xxxxxx'  # 发送邮件的【邮箱密码】
EMAIL_SUBJECT_PREFIX = u'[prefix]'  # 为邮件Subject-line前缀,默认是'[django]'
EMAIL_USE_TLS = False  # 与SMTP服务器通信时,是否启动TLS链接(安全链接)。默认是false
SERVER_EMAIL = 'webmaster@xxxx.com.cn' 
ADMINS = (('webmaster','webmaster@xxxx.com.cn'),)  # 接收邮件的邮箱(或邮件组)
  • 邮件内容
# view  logger.error('发送到邮件的日志')
# title [django_ops]ERROR: 发送到邮件的日志
# 邮件内容
发送到邮件的日志

Report
发送到邮件的日志

Django Version: 3.0.6
Python Executable: /home/jenvid/PycharmProjects/01myproject/ops_env/bin/python3.7
Python Version: 3.7.5
Python Path: ['/home/jenvid/PycharmProjects/django/ops/apps', '/home/jenvid/PycharmProjects/django/ops', '/usr/local/pycharm-2019.3.1/plugins/python/helpers/pycharm_display', '/home/jenvid/PycharmProjects/01myproject/ops_env/lib/python37.zip', '/home/jenvid/PycharmProjects/01myproject/ops_env/lib/python3.7',
二.参数

https://docs.djangoproject.com/en/3.0/topics/logging/#django.utils.log.AdminEmailHandlerhttps://docs.djangoproject.com/en/3.0/ref/settings/#std:setting-EMAIL_HOST

Email¶
ADMINS
DEFAULT_CHARSET
DEFAULT_FROM_EMAIL
EMAIL_BACKEND
EMAIL_FILE_PATH
EMAIL_HOST
EMAIL_HOST_PASSWORD
EMAIL_HOST_USER
EMAIL_PORT
EMAIL_SSL_CERTFILE
EMAIL_SSL_KEYFILE
EMAIL_SUBJECT_PREFIX
EMAIL_TIMEOUT
EMAIL_USE_LOCALTIME
EMAIL_USE_TLS
MANAGERS
SERVER_EMAIL
  • ADMINS
Default: [] (Empty list)

A list of all the people who get code error notifications. When DEBUG=False and AdminEmailHandler is configured in LOGGING (done by default), Django emails these people the details of exceptions raised in the request/response cycle.

Each item in the list should be a tuple of (Full name, email address). Example:
[('John', 'john@example.com'), ('Mary', 'mary@example.com')]
  • DEFAULT_CHARSE
Default: 'utf-8'

Default charset to use for all HttpResponse objects, if a MIME type isn’t manually specified. Used when constructing the Content-Type header.
  • DEFAULT_FROM_EMAIL
Default: 'webmaster@localhost'

Default email address to use for various automated correspondence from the site manager(s). This doesn’t include error messages sent to ADMINS and MANAGERS; for that, see SERVER_EMAIL.
  • EMAIL_BACKEND
Default: 'django.core.mail.backends.smtp.EmailBackend'

The backend to use for sending emails. For the list of available backends see Sending email.
  • EMAIL_FILE_PATH
Default: Not defined

The directory used by the file email backend to store output files.
  • EMAIL_HOST
Default: 'localhost'

The host to use for sending email.

See also EMAIL_PORT
  • EMAIL_PORT
Default: 25

Port to use for the SMTP server defined in EMAIL_HOST
  • EMAIL_USE_LOCALTIME
Default: False

Whether to send the SMTP Date header of email messages in the local time zone (True) or in UTC (False).
  • EMAIL_SSL_CERTFILE
Default: None

If EMAIL_USE_SSL or EMAIL_USE_TLS is True, you can optionally specify the path to a PEM-formatted certificate chain file to use for the SSL connection.
  • EMAIL_SSL_KEYFILE
Default: None

If EMAIL_USE_SSL or EMAIL_USE_TLS is True, you can optionally specify the path to a PEM-formatted private key file to use for the SSL connection.

Note that setting EMAIL_SSL_CERTFILE and EMAIL_SSL_KEYFILE doesn’t result in any certificate checking. They’re passed to the underlying SSL connection. Please refer to the documentation of Python’s ssl.wrap_socket() function for details on how the certificate chain file and private key file are handled.
  • EMAIL_TIMEOUT
Default: None

Specifies a timeout in seconds for blocking operations like the connection attempt.
  • EMAIL_SUBJECT_PREFIX
Default: '[Django] '

Subject-line prefix for email messages sent with django.core.mail.mail_admins or django.core.mail.mail_managers. You’ll probably want to include the trailing space.
  • EMAIL_USE_TLS
Default: False

Whether to use a TLS (secure) connection when talking to the SMTP server. This is used for explicit TLS connections, generally on port 587. If you are experiencing hanging connections, see the implicit TLS setting EMAIL_USE_SSL
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jenvid.yang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值