I'm trying to send emails in my Django project, but I have some problems. I've found many similar questions, but I couldn't cope with the problem. Could you please tell me what I need to do to be able to send emails. This is a part of settings.py:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'mymail@gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
This is my function from views.py:
def add_comment(request, wish_list_id):
wish_list = get_object_or_404(Wish_list, pk=wish_list_id)
if request.method == 'POST':
form = Comment_to_wish_listForm(request.POST)
if form.is_valid():
newform=form.save(commit=False)
newform.person = request.user
newform.comment_to = wish_list
newform.save()
cd = form.cleaned_data
send_mail(
'New comment',
cd['text'],
'fromexample@gmail.com',
['toexample@gmail.com'],
)
return HttpResponseRedirect(reverse('friends_plans:comment', args=(wish_list.id,)))
else:
print form.errors
else:
form = Comment_to_wish_listForm()
context_dict = {'form': form, 'wish_list': wish_list}
return render(request, 'friends_plans/add_comment.html', context_dict)
I get the error SMTPAuthenticationerror (535,Username and Password not accepted). And the same mistake when I use shell commands. I also tried to use Sendgrid as it is advised in some cases, but I get the same mistake.
I followed the link Django SMTPAuthenticationError and make the steps as it is advised: 1. I followed the link and allowed access to my Google account. 2. And i choose 'turn on' for 'Access for less secure apps'. But this didn't help, I have the same mistake!