send email with django

1,206 views
Skip to first unread message

shahab emami

unread,
Apr 18, 2017, 5:25:33 PM4/18/17
to Django users
hello

i want to send email using django. i used to send email with pour python before but now i can't do that in django.

i have search about this and i have seen some tutorials on youtube  in last two days but i cant do this .

this is in my settings.py :

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'my_g...@gmail.com'
EMAIL_HOST_PASSWORD= 'my_password'
EMAIL_PORT = 587

and this is my send email:

from django.core.mail import send_mail
def click(request):
    send_mail(
        'shahab',
        'Here is the message.',
        'my_g...@gmail.com',
        ['shaha...@yahoo.com'],
        fail_silently=True
    )   
    return HttpResponseRedirect('index')

but it doesn't work.

I am running this code on localhost. but i doesn't work on heroku too.
i changed allow less secure app to on in my gmail account and
i went to this page too and  i clicked on continue :
https://accounts.google.com/DisplayUnlockCaptcha

can anybody tell me:
what am i missing ?



Antonis Christofides

unread,
Apr 19, 2017, 2:32:12 AM4/19/17
to django...@googlegroups.com

Hi,

I may be mistaken, but I think it's not possible to use Gmail as a smarthost if all you have is a free account, and even if it is possible, it is hard to setup. Better try another email provider or with a paid account.

Regards,

A.

Antonis Christofides
http://djangodeployment.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/65e0ab09-ff5a-4ed5-89d6-e5e0991b9ea0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jani Tiainen

unread,
Apr 19, 2017, 6:57:30 AM4/19/17
to django...@googlegroups.com

Have you enabled app in Google mail account?

You can do that through url https://accounts.google.com/DisplayUnlockCaptcha
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/65e0ab09-ff5a-4ed5-89d6-e5e0991b9ea0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
Jani Tiainen

Jani Tiainen

unread,
Apr 19, 2017, 7:00:51 AM4/19/17
to django...@googlegroups.com

Also, don't fail silently it would be helpful to see actual error that happens...


On 19.04.2017 00:25, shahab emami wrote:
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/65e0ab09-ff5a-4ed5-89d6-e5e0991b9ea0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
Jani Tiainen

shahab emami

unread,
Apr 19, 2017, 7:56:25 AM4/19/17
to Django users
i have seen a few tutorial that use Gmail account for sending email.
like this:

http://stackoverflow.com/questions/31324005/django-1-8-sending-mail-using-gmail-smtp

https://www.youtube.com/watch?v=51mmqf5a0Ss
and more.
but tried with yahoo email too . then i changed my settings.py to this:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.mail.yahoo.com'
EMAIL_HOST_USER = 'my_yahoo_account'
EMAIL_HOST_PASSWORD = 'my_password'
EMAIL_PORT = 587

but it steel doesn't work.

Carl

unread,
Apr 19, 2017, 8:22:37 AM4/19/17
to django...@googlegroups.com
As a counter-perspective, we have this working with a paid G Suite (formerly Google Apps) account. *Important* We had to register the IP address of our server with G Suite. This Google support document outlines the process:
  SMTP relay: Route outgoing non-Gmail messages through Google

In terms of Django, our settings.py file has the following relevant settings:

# To have error messages auto-sent via email:
SERVER_EMAIL = 'myn...@mypaid-gmail.com'
ADMINS = [('MyWebServer', 'myn...@mypaid-gmail.com'),]

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp-relay.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
DEFAULT_FROM_EMAIL = 'myn...@mypaid-gmail.com'
DEFAULT_TO_EMAIL = 'myn...@mypaid-gmail.com'

Hope this helps!

Thiago Luiz Parolin

unread,
Apr 19, 2017, 9:48:38 AM4/19/17
to django...@googlegroups.com
i am using sendgrid for send emails...the free service works very well for me...there is a paid version too..
sendgrid can be integrated into django

https://sendgrid.com/docs/Integrate/Frameworks/django.html




To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

-- 
Jani Tiainen


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

shahab emami

unread,
Apr 19, 2017, 3:56:11 PM4/19/17
to Django users
but it's free for 30 days. what i have to do after 30 days?
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

-- 
Jani Tiainen


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

sum abiut

unread,
Apr 19, 2017, 5:08:53 PM4/19/17
to django...@googlegroups.com
I am also using sendgrid it works very well.

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

shahab emami

unread,
Apr 19, 2017, 5:48:55 PM4/19/17
to Django users
but that doesn't work for me too.

i sign up in sendgrid and this is my new settings.py

EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'my_account'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

not on localhost and not on heroku

sum abiut

unread,
Apr 19, 2017, 7:09:17 PM4/19/17
to django...@googlegroups.com
Have you install the sendgrid backend?

what is the error message you are getting


To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Antonis Christofides

unread,
Apr 20, 2017, 4:59:42 AM4/20/17
to django...@googlegroups.com

You might also want to read this article of mine, which might give you lots of ideas about what could be wrong: Why does Django not email me the 500 internal server error?

Regards,

A.

Antonis Christofides
http://djangodeployment.com

Christian Ledermann

unread,
Apr 20, 2017, 9:04:32 AM4/20/17
to django...@googlegroups.com
try https://www.mailgun.com if you don't want to host your own smtp server

On 20 April 2017 at 09:57, Antonis Christofides
> https://groups.google.com/d/msgid/django-users/82fe4c4f-91c8-8cf0-b8b9-2f1d4d8cb75c%40djangodeployment.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Best Regards,

Christian Ledermann

Newark-on-Trent - UK
Mobile : +44 7474997517

https://uk.linkedin.com/in/christianledermann
https://github.com/cleder/


<*)))>{

If you save the living environment, the biodiversity that we have left,
you will also automatically save the physical environment, too. But If
you only save the physical environment, you will ultimately lose both.

1) Don’t drive species to extinction

2) Don’t destroy a habitat that species rely on.

3) Don’t change the climate in ways that will result in the above.

}<(((*>
Reply all
Reply to author
Forward
0 new messages