Django send Email


from django.core.mail import send_mail

send_mail('Subject here', 'Here is the message.', '[email protected]',    ['[email protected]'], fail_silently=False)

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

email = EmailMessage('Hello', 'Body goes here', '[email protected]',
            ['[email protected]', '[email protected]'], ['[email protected]'],
            headers = {'Reply-To': '[email protected]'})

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

Html email

from django.core.mail import EmailMultiAlternatives

subject, from_email, to = 'hello', '[email protected]', '[email protected]'
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

Your comment:

Your Name

Comment:




Last articles