Reputation: 3447
I'm using EmailMessage to send emails via Amazon SES in Django. I am currently having trouble inserting new lines in the message. "\n" does not seem to work
How do I go about doing this?
As an example, this is what I've tried:
subject= "Test email with newline"
message = "%s %s is testing an email with a newline. \nCheck out this link too: http://www.example.com" % (user.first_name, user.last_name)
from_string = "<[email protected]>"
email_message = EmailMessage(subject, message, from_string, [user.email])
email_message.send()
When I send this email I get:
Michael Smith is testing an email with a newline. Check out this link too:
http://www.example.com
However, I expected the email to be formatted like this:
Michael Smith is testing an email with a newline.
Check out this link too: http://www.example.com
Upvotes: 1
Views: 1766
Reputation: 5873
The better use is case it try sending html message where you can send email as html. There you can format your msg like whatever you want
Upvotes: 0
Reputation: 731
You can use attach_alternative() and provide html - in your case <p>
or <br>
will do the trick.
or
from django.core.mail import EmailMessage
subject= "Test email with newline"
html_context = "%s %s is testing an email with a newline. <br>Check out this link too: http://www.example.com" % (user.first_name, user.last_name)
from_string = "<[email protected]>"
msg = EmailMessage(subject,
html_context,
from_string,
[user.email])
msg.content_subtype = "html"
msg.send()
Upvotes: 1