[Django]-Django:Setting up email

3πŸ‘

βœ…

You should setup from_email parameter (as a kwarg or 3rd arg) with EmailMessage call. Or define in settings.py:

DEFAULT_FROM_EMAIL = 'some.mail@inter.net'

This is taken as default if no from_email is provided to EmailMessage.

On a semi-related note, it’s probably a good idea to also define SERVER_EMAIL in settings.py. This one is used with mail_admins and mail_managers by Django.

πŸ‘€frnhr

1πŸ‘

All your settings are correct and complete, you just missed one thing at the end. You created a mail object and now email is ready to be sent email object, but you need to actually send it with email.send(). For more info and examples check Django documentation. Also, you can use send_mail which automatically creates the email object and sends it.

from django.core.mail import send_mail

mail_title = 'Hello!'
message = 'Have you received this mail?'
email = 'admin@company.com'
recipients = 'someone@gmail.com'

send_mail(mail_title, message, email, [recipients])
πŸ‘€Scillon

0πŸ‘

According to the following link https://docs.djangoproject.com/en/1.3/topics/email/, you should put email in brackets. That means, it should look like this:

from django.core.mail.import send_mail

mail_title = 'Hello!'
message = 'Have you received this mail?'
email = admin@company.com
recipients = 'someone@gmail.com'

send_mail(mail_title, message, email, [recipients])
πŸ‘€vcvd

Leave a comment