Reputation: 1284
I would like to send email message with newlines. Let say, by following code:
send_mail("subject", "Hi George\n Thanks for registration", "from", "to")
I expect:
Hi George
Thanks for registration
Whereas that what I get is: Hi George\n Thanks for registration
Email is send to a gmail account if that matters.
Any ideas?
Thanks!
Upvotes: 7
Views: 8575
Reputation: 1
Hello this is working for me using "f" string see example bellow.
f'New contact from : {message_name} \n Email: {message_email} \n
Subject: {message_subject} \n Message:{message_content}'
Upvotes: 0
Reputation: 1950
The best way you can accomplish that is by puting the mail text in template and use django template loader to render it with context.
from django.template.loader import render_to_string
context = {} # Fill it with your context
send_mail(
'Subject',
render_to_string('core/emails/email.txt', context),
'[email protected]',
['[email protected]'],
fail_silently=False)
Upvotes: 4