Django가 관리자에게 이메일을 보내지 않음
에 따르면 문서 , 경우이 DEBUG설정되어 False무언가가 아래에 제공되는 ADMINS코드가 500 상태 코드를 제기 할 때마다 설정, 장고 이메일을 보내드립니다. 이메일 설정을 올바르게 작성했지만 (send_mail을 잘 사용할 수 있으므로) 의도적으로 잘못된 코드를 입력 할 때마다 500.html 템플릿을 얻지 만 오류 이메일이 전송되지 않습니다. 장고가 이것을하지 못하게하는 원인은 무엇입니까?
제 경우에는 원인에 SERVER_EMAIL 설정 이 누락되었습니다 .
의 기본값은 SERVER_EMAIL입니다 root@localhost. 그러나 내 이메일 제공 업체를 포함한 많은 이메일 서버는 그러한 의심스러운 주소에서 오는 이메일을받지 않습니다. 그들은 조용히 이메일을 삭제합니다.
발신자 이메일 주소를 변경하여 django@my-domain.com문제 를 해결했습니다. 에서 settings.py:
SERVER_EMAIL = 'django@my-domain.com'
오류의 또 다른 가능성은 ADMINS 설정 문제입니다. 다음 설정을 사용하면 관리자에게 메일 보내기가 조용히 실패합니다.
ADMINS = (
('your name', 'me@mydomain.com')
)
그게 무슨 문제입니까? Well ADMINS는 튜플의 튜플이어야하므로 위의 형식은 다음과 같이 지정해야합니다.
ADMINS = (
('your name', 'me@mydomain.com'),
)
후행 쉼표에 유의하십시오. 실패한 쉼표가 없으면 이메일의 '받는 사람'주소의 형식이 잘못 지정되고 SMTP 서버에서 자동으로 삭제 될 수 있습니다.
저도 같은 상황이었습니다. 나는 새로운 프로젝트와 앱을 만들었고 그것이 작동했기 때문에 그것이 내 코드라는 것을 알았습니다. settings.py의 LOGGING 사전으로 추적했습니다. 몇 주 전에 Sentry로 로깅하기 위해 몇 가지 변경 사항을 적용했지만 어떤 이유로 오류가 오늘 시작되었습니다. 원본으로 다시 변경하여 작동하게했습니다.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
그런 다음 천천히 변경하여 Sentry와 함께 작업하고 ADMINS에게 이메일을 보냅니다.
또한 LOGGING구성은 DEFAULT_LOGGING기본적으로 병합 되므로 특정 상황에 어떤 영향을 미칠 수 있는지 이해 하려면의 소스 코드를django.utils.log.DEFAULT_LOGGING 살펴 보는 것이 좋습니다.
EMAIL_HOST 및 EMAIL_PORT가 settings.py에서 올바르게 설정되어 있는지 확인하세요 (SMTP 서버 참조). localhost에서 실행중인 SMTP 서버가 있다고 가정 할 수 있습니다.
이를 로컬에서 테스트하려면 Python의 기본 제공 테스트 SMTP 서버를 실행합니다.
python -m smtpd -n -c DebuggingServer localhost:1025
그런 다음 settings.py에서 이러한 값을 설정하십시오.
EMAIL_HOST='localhost'
EMAIL_PORT=1025
500 오류가 발생하면 python smtpd 터미널 창에 전자 메일이 표시됩니다.
내 웹 호스팅 제공 업체-Webfaction-관리자 패널에서 명시 적으로 생성 된 이메일에서만 이메일을 보낼 수 있습니다. 하나를 만들면 문제가 해결되었습니다.
여기서 주목할 가치가있는 또 다른 점 handler500은보기의 응답에 상태 코드가 500이 아니면 handler500설정 이 500에 오류를 보내는 메커니즘을 우회 할 수 있다는 것입니다. 세트 가있는 경우 해당보기에서 이와 같은 응답으로 응답합니다.
t = loader.get_template('500.html')
response = HttpResponseServerError(
t.render(RequestContext(request, {'custom_context_var':
'IT BROKE OMG FIRE EVERYONE'})))
response.status_code = 500
return response
이 시도
# ./manage shell
>>> from django.core.mail import send_mail
>>> send_mail('Subject here', 'Here is the message.', 'from@example.com',['to@example.com'], fail_silently=False)
실제로 이메일을받는 to@example.com으로.
DEBUG = False인지 확인하십시오.
너무 순진한 경우 죄송하지만 제 경우에는 이메일이 전송되었지만 스팸 폴더로 직접 이동했습니다. 더 복잡한 작업을 시도하기 전에 먼저 스팸 폴더를 확인하십시오.
오랜만에 다른 사람들이 혜택을받을 수 있도록 내 답변입니다.
제 경우에는 오류가 발생했을 때 ADMINS 목록에 이메일이 전송되지 않도록하는 것은 애플리케이션 별 설정이었습니다. 나는 설정 속성 PISTON_EMAIL_ERRORS 및 PISTON_DISPLAY_ERRORS를 제공하는 django-piston을 사용하고있었습니다. 이에 따라 설정하면 애플리케이션 서버가 피스톤이 충돌 할 때마다 메일로 알림을 보낼 수 있습니다.
어떤 이유로 DEBUG_PROPAGATE_EXCEPTIONS를 True (기본값은 False)로 설정하면 관리자에게 보내는 이메일이 작동하지 않습니다.
... 그리고 이메일이 나가는 것을 막기 위해 개발에서 이것을 사용한 후 실수로 설정을 프로덕션에 복사했을 때 facepalm 오류가 있습니다.
# Print emails to console
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
(물론 wsgi 서버를 사용할 때 콘솔에 인쇄되는 것을 볼 수 없습니다). 프로덕션에서 설정을 제거하면이 문제가 해결되었습니다.
그리고 잘못 될 수있는 또 다른 사항 (위의 모든 훌륭한 답변에도 불구하고 여기에 도착하는 사람들을 위해 목록에 추가하겠습니다) :
우리의 django 설정은 SendGrid를 smtp 호스트로 사용했으며 django 설정에 정의 된 단일 관리자 이메일 주소가 있습니다. 이것은 한동안 잘 작동했지만 어느 시점에서 메일 도착이 중단되었습니다.
밝혀진 바와 같이 메일 주소는 알 수없는 이유로 SendGrid 'Bounced'목록에 포함되어 해당 주소에 대한 이메일이 자동으로 영원히 삭제되었습니다. 해당 목록에서 주소를 제거하고 허용 목록에 추가하면 문제가 해결되었습니다.
SendGrid를 사용 중이거나 사용하려는 경우 프로덕션에서 아래 설정을 사용하십시오.
패키지 설치
pip install sendgrid-django
settings.py (production)에 이러한 설정을 추가하십시오.
DEBUG = False
EMAIL_BACKEND = "sendgrid_backend.SendgridBackend"
SENDGRID_API_KEY = "That you generate in sendgrid account"
ADMINS = (
("Your Name", "your_email@company.com")
)
Just had the same issue after upgraded to Django 2.1 from Django 1.11. Apparently the ADMINS sections in settings.py has a change. It takes a list of tuples now, rather than the old tuple of tuples. This fixed for me.
##### old #####
ADMINS = (
("Your Name", "your_email@company.com")
)
##### new #####
ADMINS = [
("Your Name", "your_email@company.com")
]
Re: https://docs.djangoproject.com/en/2.1/ref/settings/#admins
While likely not ideal, I have found using Gmail as the SMTP host works just fine. There is a useful guide at nathanostgard.com.
Feel free to post your relevant settings.py sections (including EMAIL_*, SERVER_EMAIL, ADMINS (just take out your real email), MANAGERS, and DEBUG) if you want an extra set of eyes to check for typos!
For what it's worth I had this issue and none of these suggestions worked for me. It turns out that my problem was that SERVER_EMAIL was set to an address that the server (Webfaction) didn't recognise. If this site were hosted on Webfaction (as my other sites are), this wouldn't be a problem, but as this was on a different server, the Webfaction servers not only check the authentication of the email being sent, but also the From: value as well.
In my case, it's the include_html in mail_admins.
When I set include_html to True,the email server reject to send my email because it think that my emails are spam.
Everything works just fine when I set include_html to False.
The below info is given in https://docs.djangoproject.com/en/2.1/howto/error-reporting/#email-reports
EMAIL_HOST = "email host"
EMAIL_HOST_USER = "Email username"
EMAIL_HOST_PASSWORD = "Email Password"
DEBUG = False
ADMINS = (
("Your Name", "your_email@company.com")
)
In order to send email, Django requires a few settings telling it how to connect to your mail server. At the very least, you’ll need to specify EMAIL_HOST and possibly EMAIL_HOST_USER and EMAIL_HOST_PASSWORD, though other settings may be also required depending on your mail server’s configuration. Consult the Django settings documentation for a full list of email-related settings.
This problem annoyed me sufficiently to motivate a post. I provide here the steps I took to resolve this problem (cutting a long story short):
- Set-up test page to fail (by re-naming test_template.html)
- Check email validations through views for test page in production using send_mail('Hello', 'hello, world', 'info@xyz.com', [('Name', 'name.name@xyz.com'),], fail_silently=False) where SERVER_EMAIL = 'info@xyz.com' and ADMINS = [('Name', 'name.name@xyz.com'),] in Django settings. In my case, I received the 'hello world' email, but not the Django admin email (which was a pain).
- Set-up a simple custom logger to report to a file on the server:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'errors_file': {
'level': 'ERROR',
'class': 'logging.FileHandler',
'filename': 'logs/debug.log',
},
},
'loggers': {
'django': {
'handlers': ['errors_file'],
'level': 'ERROR',
'propagate': True,
},
},
}
In my case, navigating to the test page did not generate output in the debug.log file under the logs directory from my project root directory. This indicates that the logger was failing to reach an ERROR 'level'.
- Downgrade the threshold for reporting for the custom logger from ERROR to DEBUG. Now, navigating to the test page should deliver some detail. Inspecting this detail revealed in my case that the default 500 page was re-directed (inadvertedly) to an alternative template file called 500.html. This template file made use of a variable for caching, and as the template was not being called through a view that made the variable available in the context, the cache call failed with a missing key reference. Re-naming 500.html solved my problem.
참고URL : https://stackoverflow.com/questions/1414130/django-not-sending-emails-to-admins
'IT TIP' 카테고리의 다른 글
| "어떤 저장소에서도 유효한 gem을 찾을 수 없습니다"(rubygame 및 기타) (0) | 2020.11.25 |
|---|---|
| 미디어 유형 = application / json에 대한 MessageBodyWriter를 찾을 수 없습니다. (0) | 2020.11.25 |
| 버튼의 클릭 이벤트 핸들러에서 대화 상자가 닫히지 않도록 방지 (0) | 2020.11.25 |
| SQLSERVER의 ListAGG (0) | 2020.11.25 |
| Spring Boot에 보조 서블릿을 등록하려면 어떻게해야합니까? (0) | 2020.11.25 |