I like to use EmailMultiAlternatives for the case of submissions with txt and html alternatives. If you want to use it one way to do it is:
from django.template.loader import render_to_string
from django.core.mail import EmailMultiAlternatives
message_html = render_to_string('seutemplate.html', dict_contexto)
message_txt = render_to_string('seutemplate.txt', dict_contexto)
subject = u"Um assunto"
from_email = u'[email protected]'
msg = EmailMultiAlternatives(subject, message_txt, from_email,
['[email protected]'])
msg = msg.attach_alternative(message, "text/html")
msg.send()
Or if you want something simpler, you can choose the default django function, send_mail . Example:
from django.core.mail import send_mail
send_mail('Subject here', 'Here is the message.', '[email protected]',
['[email protected]'], fail_silently=False)
Remembering that for the submission to work, you'll need to set up a sending backend with the settings variable EMAIL_BACKEND. To test location you can use the backend console, where the message, after sending, will appear in the shell. To use the backend console, assign the following value to the EMAIL_BACKEND:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'