I’m using django send_mail like this:
JavaScript
x
4
1
from django.core.mail import send_mail
2
3
send_mail('Test', 'asdfasdfasdfnasdfasfasdfasdfnasdfasdfasdf', 'sender@test.com', ['receiver@test.com'], fail_silently=False)
4
Gmail recieves this.
JavaScript
1
18
18
1
Content-type: multipart/alternative; boundary="----------=_1382512224-21042-56"
2
------------=_1382512224-21042-56
3
Content-Type: text/plain; charset="utf-8"
4
Content-Transfer-Encoding: 7bit
5
6
asdfasdfasdf
7
asdfasfasdfasdf
8
asdfasdfasdf
9
10
------------=_1382512224-21042-56
11
Content-Type: text/html; charset="utf-8"
12
Content-Disposition: inline
13
Content-Transfer-Encoding: 7bit
14
15
<html><body>
16
<p>asdfasdfasdf asdfasfasdfasdf asdfasdfasdf</p>
17
</body></html>
18
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().
JavaScript
1
11
11
1
from django.core.mail import EmailMessage
2
3
msg = EmailMessage(
4
'Test',
5
'asdfasdfasdf<br>asdfasfasdfasdf<br>asdfasdfasdf',
6
'sender@example.com',
7
['receiver@example.com', ]
8
)
9
msg.content_subtype = "html"
10
msg.send()
11