[Answered ]-Send different attachment files such as picture, pdf, audio files, video files and zip files via email in Django

1👍

just remove the .url from book_object and send the book_object.read()

def send_book(request):
    subject= 'the subject of this email'
    message = 'body of this email'
    recipient_email = 'customer@example.com'
    from_email = 'platformemail@example.com'
    email=EmailMessage(subject,message,from_email,[recipient_email])
    email.content_subtype='html'

    # the_domain = request.build_absolute_uri('/')[:-1]
    book_object = Book.objects.get(title='Selfish Gene').bookfiles_set.all().first().file
    # the_file=open(f'{the_domain}{book_object}',"r")
    email.attach("file_name.pdf", book_object.read(),'application/pdf')

    email.send()

0👍

Have you set the MEDIA_ROOT in your settings.py to the absolute path to where the files resides on the disk? And , if so, what is it set to?

As a reference to media settings in Django, have a look at this article:
https://testdriven.io/blog/django-static-files/#media-files

Leave a comment