Y
Y
Yura Khlyan2019-02-26 13:32:36
Django
Yura Khlyan, 2019-02-26 13:32:36

Why is the entire text of the email on one line?

Good day.
I create an email:

...
subject = loader.render_to_string(f'{path_email_template_folder}/subject.txt', context).replace('\n', ' ')
text_msg = loader.get_template(f'{path_email_template_folder}/body.txt').render(context)
html_msg = loader.get_template(f'{path_email_template_folder}/body.html').render(context)
send_mail(
            subject, text_msg, email_from or settings.DEFAULT_FROM_EMAIL, [user.email],
            fail_silently=False, html_message=html_msg
)

Sample:
From now on, please log in to your account using your email address.
Your account details are as follows:

Password: {{ password }}
Broker key: {{ broker_key }}

Thank you for using our software

But everything comes to the mail in one line. Here's what's in the GMAIL sources:
--===============9031269262700428934==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

From now on, please log in to your account using your email address.
Your account details are as follows:

Password: KVSx4jByPy
Broker key: 11111

Thank you for using our software,
--===============9031269262700428934==
Content-Type: text/html; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

From now on, please log in to your account using your email address.
Your account details are as follows:

Password: KVSx4jByPy
Broker key: 11111

Thank you for using our software,
--===============9031269262700428934==--

What could be the problem? Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Dubrovin, 2019-02-26
@MAGistr_MTM

By default, the HTML part of the email is displayed; in order to transfer the HTML, you need to add the tag <br>. If you do not want to format HTML - leave only the text part of the letter.

L
Larisa .•º, 2019-02-26
@barolina

Explicitly specify line breaks in pattern \r\n

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question