python - Django sending email with google SMTP -


i have been trying emails working django application , have not been able to. ive been reading around on similar questions , still haven't been able pin point error.

my settings.py looks :

email_host = 'smtp.gmail.com' email_host_user = 'email@domain' email_host_password = 'pass' email_port = 587 email_use_tls = true email_backend = 'django.core.mail.backends.smtp.emailbackend' 

my code send email looks :

def application(request):          if request.method == 'get':                 form = applyform()         else:                 form = applyform(request.post)                 if (form.is_valid()):                         try:                                 subject = 'overland application'                                 from_email = form.cleaned_data['useremail']                                 phone = form.cleaned_data['phone']                                 names = form.cleaned_data['names']                                 year = form.cleaned_data['year']                                 make = form.cleaned_data['make']                                 model = form.cleaned_data['model']                                 message = str(names) + '\n' + str(from_email) + '\n' + str(phone) + '\n' + str(year) + '\n' + str(make) + '\n' + str(model)                                 try:                                         send_mail(subject, message, settings.email_host_user, ['email@domain.com'], fail_silently=false)                                 except badheadererror:                                         return httpresponse('invalid header found.')                                 return redirect('thanks')                         except:                                 pass         return render(request, "overland/apply.html", {'form': form}) 

some additional information seems accessing email account did receive email google saying there suspicious access on account location of server.

i pinged smtp server live server make sure communicating.

i not sure if small syntax error on part somewhere or using django mail function incorrectly because locally seemed work , redirect page, when live seems reload page , not send anything.

thanks in advance information.

this issue gmail itself. running issue should first try going security settings , allowing access less secure apps. if doesn't work try visiting https://accounts.google.com/displayunlockcaptcha , use application send email again.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -