1
我想設置發送電子郵件與Django超時。我使用的是django 1.7.3和python v2.7.6。我的意見是遵循here中的django文檔。所以我所做的就是通過創建一個名爲myemailbackend.py上的Django /核心/郵件/後端文件夾下面的代碼文件中創建一個自定義郵件後端:如何設置使用django發送電子郵件的超時時間?
from django.core.mail.backends import smtp
class MyEmailBackend(smtp.EmailBackend):
def __init__(self, *args, **kwargs):
kwargs.setdefault('timeout', 3) #this is 3 secs, i believe.
super(MyEmailBackend, self).__init__(*args, **kwargs)
後,在我的settings.py設置我EMAIL_BACKEND :
# Email setup
EMAIL_BACKEND = 'django.core.mail.backends.base.myemailbackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'xxx'
EMAIL_PORT = 587
# EMAIL_TIMEOUT = 3 # 3 sec, this would be great but i notice that this is not possible since that backend stmp.py doesn't expect to get "EMAIL_TIMEOUT" var.
後我RUNSERVER我注意到,這似乎並沒有工作,我發現到myemailbackend.py沒有被編譯。 我失蹤了什麼?如何設置發送電子郵件的超時時間?