0

Не получается сгенерировать pdf и отправить его приложением на email.

def send_email_info(request, *args, **kwargs):
        address = f"{response.data['profile']}."
        context = {
             "org_address": address,
        }
        pdf = render_to_pdf(context).getvalue()
        subject = "Welcom!"
        email_msg = EmailMessage(subject, body=pdf, from_email='[email protected]', to=['[email protected]'])
        email_msg.attach('address.pdf', pdf, "application/pdf")
        email_msg.content_subtype = "pdf"  
        email_msg.encoding = 'UTF-8'
        email_msg.send()

и функция, которая отвечает за рендер pdf

def render_to_pdf(context):
    html = render_to_string('cabinet/registration_data.html', context)
    result = BytesIO()
    pdf = pisa.pisaDocument(BytesIO(html.encode("UTF-8")), result, encoding='utf-8', link_callback=fetch_pdf_resources)
    if not pdf.err:
        return result
    else:
        return None

Ошибка не возникает, но и письмо не приходит. SMTP настроен правильно, потому что письма без из другой функции PDF приходят. Не понимаю, как исправить ситуацию.

7

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Посмотрите другие вопросы с метками или задайте свой вопрос.