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()