0
連絡先フォームで作業していて、Djangoからの電子メールを受信トレイに受信できません。Djangoは電子メール通知を送信しません
これは私の関数である。
def contact(request):
if request.method == 'GET':
form = ContactForm()
else:
form = ContactForm(request.POST)
if form.is_valid():
contact_name = form.cleaned_data['contact_name']
contact_phone = form.cleaned_data['contact_phone']
contact_period = form.cleaned_data['contact_period']
subject = contact_name + " | " + contact_phone + " | " + contact_period
content = form.cleaned_data['content']
contact_email = form.cleaned_data['contact_email']
try:
send_mail(subject,content,contact_email, ['[email protected]'])
except BadHeaderError:
return HttpResponse('Invalid header found.')
return redirect('success')
return render(request, "contact.html", {'form': form})
def success(request):
return HttpResponse('Success! Thank you for your message.')
これらは私のサーバーの設定です:
Secure SSL/TLS Settings (Recommended)
Username: [email protected]
Password: Use the email account’s password.
Incoming Server: mail.cohen.ro
IMAP Port: 993 POP3 Port: 995
Outgoing Server: mail.cohen.ro
SMTP Port: 465
は、これは私が私のDjangoの設定で持っているものです: LATEREDIT:私は、コンソールをコメントし、今持っていますこのコード行は電子メールを送信しません。私のサーバーで
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
#EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
DEFAULT_FROM_EMAIL = '[email protected]'
EMAIL_HOST= 'mail.cohen.ro'
EMAIL_HOST_USER= '[email protected]'
EMAIl_HOST_PASSWORD='mypass'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
私はメッセージを見ることができますが、私は誰かが私に何かを求めている場合は知らないので、私のメールアドレスにメールを送信しません。ありがとうございました!
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: me | 0787877 | 12-13
From: [email protected]
To: [email protected]
Date: Mon, 25 Dec 2017 11:29:39 -0000
Message-ID: <[email protected]>
me
私が得たエラー。
SMTPServerDisconnected at /contact/
Connection unexpectedly closed
Request Method: POST
Request URL: http://127.0.0.1:8000/contact/
Django Version: 2.0
Exception Type: SMTPServerDisconnected
Exception Value:
Connection unexpectedly closed
Exception Location: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/smtplib.py in getreply, line 393
Python Executable: /Users/cohen/PycharmProjects/chn/venv/bin/python
Python Version: 3.6.1
Python Path:
['/Users/cohen/PycharmProjects/chn',
'/Users/cohen/PycharmProjects/chn',
'/Users/cohen/PycharmProjects/static_in_env',
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip',
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6',
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload',
'/Users/cohen/PycharmProjects/chn/venv/lib/python3.6/site-packages',
'/Users/cohen/PycharmProjects/chn/venv/lib/python3.6/site-packages/setuptools-28.8.0-py3.6.egg',
'/Users/cohen/PycharmProjects/chn/venv/lib/python3.6/site-packages/pip-9.0.1-py3.6.egg',
'/Applications/PyCharm.app/Contents/helpers/pycharm_matplotlib_backend']
Server time: Mon, 25 Dec 2017 13:49:16 +0200
すべてのヘルプは、はるかに高く評価されるだろう!
コピー貼り付けの変更間違いがあるのかどうかはわかりませんが、 'EMAIL_HOST_PASSWORD'にはemail:' EMAIl'という単語に小文字の 'L'が含まれています。 – Nrzonline