[英]Django email backend and smtp configuration
我正在嘗試在我的 django 項目中使用我的 Zoho 帳戶,以便通過聯系人 forms 接收電子郵件。
我也遵循了這個指南: https://www.zoho.com/mail/help/zoho-smtp.html
在我寫的“settings.py”文件中:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtppro.zoho.eu'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = '<domain name email>'
EMAIL_HOST_PASSWORD = '<password>'
在 views.py 中:
def home(request):
allTemplates = AllTemplates.objects.all()
if request.method == 'POST':
form = forms.ContactForm(request.POST)
if form.is_valid():
body = {
'name': form.cleaned_data['name'],
'surname': form.cleaned_data['surname'],
'from_email': form.cleaned_data['from_email'],
'message': form.cleaned_data['message'],
}
mail_body = "\n".join(body.values())
try:
send_mail("Generic contact", mail_body, '<domain name email>',
['<domain name email>'], fail_silently=False)
except BadHeaderError:
return HttpResponse('Ops, qualcosa è andato storto')
form = forms.ContactForm
context = {'form': form, 'allTemplates': allTemplates,
'allTemplates_length': len(allTemplates)}
return render(request, 'home.html', context)
注意在“send_email”中我輸入了兩次我的 email 地址來測試
我也嘗試使用 ssl
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtppro.zoho.eu'
EMAIL_PORT = 465
EMAIL_USE_SSL = True
EMAIL_HOST_USER = '<domain name email>'
EMAIL_HOST_PASSWORD = '<password>'
但沒有,我沒有收到任何 email。
有沒有人已經通過它或者誰可以指導我找到一些文件或學習指南?
非常感謝你提前。
我用
EMAIL_PORT = 587
EMAIL_USE_TLS = True
我最大的痛苦是所有電子郵件都進入了垃圾郵件文件夾,我有 2 個小時沒有意識到這一點。
測試本地 output 到終端:
設置.py
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
設置.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST='localhost'
EMAIL_PORT=1025
並在終端 window 中啟動與運行服務器並行的本地測試郵件服務器:
python -m smtpd -n -c DebuggingServer localhost:1025
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.