Skip to content
Advertisement

Python Django send_mail newlines?

I’m using django send_mail like this:

from django.core.mail import send_mail

send_mail('Test', 'asdfasdfasdfnasdfasfasdfasdfnasdfasdfasdf', 'sender@test.com', ['receiver@test.com'], fail_silently=False)

Gmail recieves this.

Content-type: multipart/alternative; boundary="----------=_1382512224-21042-56"
------------=_1382512224-21042-56
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

asdfasdfasdf
asdfasfasdfasdf
asdfasdfasdf

------------=_1382512224-21042-56
Content-Type: text/html; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit

<html><body>
<p>asdfasdfasdf asdfasfasdfasdf asdfasdfasdf</p>
</body></html>

And shows my newlines as one whole paragraph. Why? I would like three lines of text, not one.

Advertisement

Answer

Try sending your email as HTML instead of plain text. Use EmailMessage().

from django.core.mail import EmailMessage

msg = EmailMessage(
    'Test',
    'asdfasdfasdf<br>asdfasfasdfasdf<br>asdfasdfasdf',
    'sender@example.com',
    ['receiver@example.com', ]
)
msg.content_subtype = "html"
msg.send()
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement