python - Django - Sending email works in shell, but not on localhost - ConnectionRefusedError -


i'm new django, have read on order of 50 pages (mostly , django documentation) , haven't found quite works situation.

i'm merely trying send email via send_mail function in django; although i'm hoping working through smtp on gmail, right doesn't work via localhost. when run test_email.py file i'm testing send_mail function, following error:

connectionrefusederror: [winerror 10061] no connection made because target machine actively refused it

when run same send_mail call in shell (via python manage.py shell), it's fine , displays email expect. it's once try run in django error pops up. note above error no matter permutation of following 2 sets of settings put in settings.py file:

email_backend = 'django.core.mail.backends.console.emailbackend' email_host = 'localhost' email_port = 1025 email_host_user = 'myemail@gmail.com' email_host_password = '' email_use_tls = false 

i've played around following in settings.py file, , various mixes of these settings previous set (though guess i'm getting ahead of myself seeing how localhost isn't working):

email_backend = 'django.core.mail.backends.smtp.emailbackend' email_use_tls = true email_host = 'smtp.gmail.com' email_port = 587 email_host_user = 'myemail@gmail.com' # note i'm using actual gmail address here in real life email_host_password = '****' # note i'm using actual gmail password here in real life  default_from_email = 'myemail@gmail.com' # note i'm using actual gmail address here in real life server_email = 'myemail@gmail.com' # note i'm using actual gmail address here in real life 

i'm running following command in cmd prompt off side when try run going localhost route:

python -m smtpd -n -c debuggingserver localhost:1025 

here's test_email.py file i'm trying run in django, connection refused error:

from django.core.mail import send_mail,emailmessage  django.conf import settings settings.configure()  # create tests here.  # email test #1: send email personal email myself send_mail(     'email test #1',     'test if can send email personal gmail account email account via django project.',     settings.email_host_user,     ['myemail@gmail.com'],     fail_silently=false     ) 

any thoughts on why isn't working via localhost or suggestions on other things try appreciated.

thanks!

i think there problem gmail smtp service. try using smtp service form sendgrid. free basic usage. facing same issue earlier.

in project settings.py

email_backend = 'django.core.mail.backends.smtp.emailbackend' email_host = 'smtp.sendgrid.net' email_host_user = 'sendgridusername' email_host_password = 'sedgridpasseord' email_port = 587 email_use_tls = true default_from_email = 'yourmail@site.com' 

still error

try if `smtp` service working on your server. 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -