H
H
Held69912021-10-02 04:29:49
Django
Held6991, 2021-10-02 04:29:49

How to send an Email via Django so that there is content from HTML with styles and pictures inside?

Hello, I would like to arrange sending a message through Django, the Yandex mail service (at the moment the django.core.mail library, if you need another - no problem) and that the message contains not dry text, but a well-designed html page with pictures and styles , I tried to do it by converting the file into one line, garbage came out, purely plain text, tell me, please, how can this be done?

html_content = render_to_string('./mail.html')
    send_mail('Покупка квартиры №', '',
              '[email protected]',
              ['[email protected]'],
              html_message= html_content,
              connection=connection,
              fail_silently=False)


HTML:
<div class="container" style="text-align: center;margin: 0 auto;background: #3596F5;font-family: 'Ephesis', cursive;color:#FFFFFF;font-size: 30px;width: 1050px;padding-bottom: 30px;">
    <img class="logo" style="margin-top: 30px;" src="logo.png" alt="logo">
    <p style="color:#FFFFFF">Congratulations on the purchase of apartment No. 120 in the residential complex "Melody"<br>
        We will contact you in the near future to clarify the information and paperwork.<br>
        When the documents are ready, the documents for the apartment and the keys will be delivered to you.</p>
    <div class="div-seal" style="display: flex;justify-content: space-evenly;align-items: center;">
        <p style="color:#FFFFFF">Best regards, founder of the company "Melody Limited Co"<br></p>
        <img src="seal.png" alt="seal">
    </div>
</div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Nesterov, 2021-10-02
@Held6991

Use html_message

send_mail(
        'Подтверждение регистрации', # Заголовок
        '', # Текстовое тело, которое не нужно
        settings.EMAIL_HOST_USER, 
        [mail],
        html_message=msg_html, # в html_message вставлять данные render_to_string
        fail_silently=False

    )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question