Django send Email

from django.core.mail import send_mail

send_mail('Subject here', 'Here is the message.', 'from@example.com',    ['to@example.com'], fail_silently=False)

========================

email = EmailMessage('Hello', 'Body goes here', 'from@example.com',
            ['to1@example.com', 'to2@example.com'], ['bcc@example.com'],
            headers = {'Reply-To': 'another@example.com'})

===============

Html email

from django.core.mail import EmailMultiAlternatives

subject, from_email, to = 'hello', 'from@example.com', 'to@example.com'
text_content = 'This is an important message.'
html_content = '<p>This is an <strong>important</strong> message.</p>'
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()


---
email.txt:

Hello {{ username }} - your account is activated.

email.html:

Hello <strong>{{ username }}</strong> - your account is activated.

--



https://docs.djangoproject.com/en/dev/topics/email/
Author: bm on July 8, 2014
Category: Python Django