In my python django project i use this two method for send html email:
def send_html_email(to_list, subject, template_name, context, sender=settings.DEFAULT_FROM_EMAIL):
msg_html = render_to_string(template_name, context)
msg = EmailMessage(subject=subject, body=msg_html,
from_email=sender, to=to_list)
msg.content_subtype = "html" # Main content is now text/html
return msg.send()
def emailsend(l_sender, l_lic, t_name='consok'):
if t_name == 'lavoraok':
templ = 'lavora_ok.html'
ttitle = 'test: Nuova candidatura da sito web'
elif t_name == 'lavoraok_cli':
templ = 'lavora_ok_cli.html'
ttitle = 'test: Nuova candidatura da sito web'
else:
templ = 'cons_del.html'
ttitle = 'test: Appuntamento cancellato'
context = {
'news': 'test consulenza',
'lic': l_lic
}
try:
send_html_email(l_sender, ttitle, templ, context,
sender='test@prova.com')
except Exception as e:
print('Email send error: ', e)
all woks well, but now in my new form i got a field for attach a file to send via email. How can i implement my defs for attach file to email?
So many thanks in advance