down votefavorite 
<https://stackoverflow.com/questions/44815104/sending-a-file-as-an-attachment-for-email-in-django#>

I am trying to send a file as an attachment in an email, the file is 
submitted through a web form. My views.py is as shown below, the problem I 
am facing is the attached file when seen in the outlook mail doesn't have 
any content in it. Is there something that I am missing here?

if request.method == 'POST':
    form = RequestForm(request.POST, request.FILES)
    if form.is_valid():
        form.save()
        messages.info(request, '')
        subject = 'abc'
        message = 'xyz'
        attachment = request.FILES['attachment']
        mail = EmailMessage(subject, message, '', [''])
        mail.attach(attachment.name, attachment.read(), attachment.content_type)
        mail.send()

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a8f25bd3-5466-4e18-a887-7a0d08512a6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to