我正在尝试在个人网站上获取联系表单。 我正在使用smtp outlook。 现在它给了我以下错误:
回溯:
Environment:
Request Method: POST
Request URL: *******
Django Version: 1.8.1
Python Version: 3.4.0
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware')
Traceback:
File "/home/Nmaster88/Ngranja/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/Nmaster88/Ngranja/Ngranja/Ngranja/views.py" in sendmail
23. send_mail(request.POST['contactSubject'],"From: "+request.POST['contactEmail']+'\n\n'+request.POST['contactMessage'],request.POST['contactEmail'],['nunomaster_@hotmail.com'],)
File "/home/Nmaster88/Ngranja/lib/python3.4/site-packages/django/core/mail/__init__.py" in send_mail
62. return mail.send()
File "/home/Nmaster88/Ngranja/lib/python3.4/site-packages/django/core/mail/message.py" in send
303. return self.get_connection(fail_silently).send_messages([self])
File "/home/Nmaster88/Ngranja/lib/python3.4/site-packages/django/core/mail/backends/smtp.py" in send_messages
100. new_conn_created = self.open()
File "/home/Nmaster88/Ngranja/lib/python3.4/site-packages/django/core/mail/backends/smtp.py" in open
58. self.connection = connection_class(self.host, self.port, **connection_params)
File "/usr/lib/python3.4/smtplib.py" in __init__
242. (code, msg) = self.connect(host, port)
File "/usr/lib/python3.4/smtplib.py" in connect
321. self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python3.4/smtplib.py" in _get_socket
292. self.source_address)
File "/usr/lib/python3.4/socket.py" in create_connection
509. raise err
File "/usr/lib/python3.4/socket.py" in create_connection
500. sock.connect(sa)
Exception Type: ConnectionRefusedError at /
Exception Value: [Errno 111] Connection refused
我的设置:
EMAIL_HOST = 'smtp-mail.outlook.com'
EMAIL_HOST_USER = 'myemail@hotmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 25
EMAIL_USE_TLS = True
查看文件:
from django.http import HttpResponseRedirect
from django.core.mail import send_mail
from django.shortcuts import render
def sendmail(request):
errors=[]
if request.method == 'POST':
if not request.POST.get('contactName',''):
errors.append('Coloca um nome.')
if not request.POST.get('contactEmail',''):
errors.append('Coloca um email.')
if not request.POST.get('contactSubject',''):
errors.append('Coloca um assunto.')
if not request.POST.get('contactMessage',''):
errors.append('Coloca um assunto.')
if not errors:
subject=request.POST['contactSubject']
email=request.POST['contactEmail']
message=request.POST['contactMessage']
send_mail(subject,"From: "+email+'\n\n'+message,email,['myemail@hotmail.com'], fail_silently=False)
return HttpResponseRedirect('/thankyou/')
return render(request, "mypage.html", {'errors': errors})
有没有人知道出了什么问题? 如有必要,我可以提供有关该应用程序的更多信息
[编辑] 我在pythonanywhere.com上托管该页面,错误是否与服务器有关?
[编辑]已解决 免费用户的Pythonanywhere仅适用于Gmail,我必须为不太安全的应用授予权限!现在它工作正常。
答案 0 :(得分:0)
尝试在use_ssl=True
设置中使用SMTP
并将端口更改为465
。
您可以直接参考Django SMTP options以获取可以调整的所有设置的列表。 另请提及您用于构建应用程序的Django版本?