[Answered ]-Attach django generated pdf in email

1👍

You can refer this function to attach pdf in your email

from django.core.mail import EmailMultiAlternatives
def send_email(subject, text_content, from_email, recepients):
    mail = EmailMultiAlternatives(subject, text_content, from_email, recepients)
    file_path = "/usr/Downloads/my.pdf"
    file = open(file_path, "r+")
    attachment = file.read()
    file.close()
    mail.attach("my.pdf", attachment, "application/pdf")
    mail.send()

Moreover, you can refer from https://docs.djangoproject.com/en/3.1/topics/email/#emailmessage-objects

Leave a comment