我试图通过django发送邮件。这是我编写的代码
from django.shortcuts import render
from django.http import HttpResponse
from django.core.mail import send_mail
def function(request):
send_mail('cheking',
'cheking django is sending mail or not',
'nithinjith40@gmail.com',
['ravisarath64@gmasil.com'],
fail_silently=False)
return render(request,'message.html')
但是显示此错误
Internal Server Error: /
Traceback (most recent call last):
File "/home/expert/project _jango/venv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/expert/project _jango/venv/lib/python3.5/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/expert/project _jango/venv/lib/python3.5/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/expert/project _jango/myproject/webapp/views.py", line 11, in function
fail_silently=False)
File "/home/expert/project _jango/venv/lib/python3.5/site-packages/django/core/mail/__init__.py", line 60, in send_mail
return mail.send()
File "/home/expert/project _jango/venv/lib/python3.5/site-packages/django/core/mail/message.py", line 291, in send
return self.get_connection(fail_silently).send_messages([self])
File "/home/expert/project _jango/venv/lib/python3.5/site-packages/django/core/mail/backends/smtp.py", line 103, in send_messages
new_conn_created = self.open()
File "/home/expert/project _jango/venv/lib/python3.5/site-packages/django/core/mail/backends/smtp.py", line 70, in open
self.connection.login(self.username, self.password)
File "/usr/lib/python3.5/smtplib.py", line 729, in login
raise last_exceptio
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials d65sm27731624pfa.159 - gsmtp')
如何解决此错误? “我启用了访问安全性较低”,然后显示相同的错误 随时在评论部分询问有关我已省略的代码行的详细信息
答案 0 :(得分:0)
这不是django错误,它看起来像gmail问题。确保您可以通过gmail网络阅读和发送邮件,并遵循gmail troubleshooting steps。但是,我建议您移至App Passwords。