Skip to content Skip to sidebar Skip to footer

Sending Email With Attached File In Django

I am trying to send and email in Django forms with attached file, but i cant figure out how to send the file(uploaded by user) without saving it locally. I have my form: class Pri

Solution 1:

Something like this:

def send_email(request):
    ...
    email = EmailMessage(
        subject,
        content,
        contact_email,
        [to],
        headers={'Reply-To': contact_email}
    )
    if request.FILES:
        uploaded_file = request.FILES['file'] # file is the name value which you have provided in form for file field
        email.attach(uploaded_file.name, uploaded_file.read(), uploaded_file.content_type)
    email.send()

Post a Comment for "Sending Email With Attached File In Django"