-1

At the current stage the email is fully working, however, when receiving the actual mail the image is not attached, rather is name is displayed. I wold like to display the attachment in order to be able to download it.

def publication(request):
    if request.method == "POST":
        inputImmagine1 = request.POST['inputImmagine1']
  
        send_mail(
            'Richiesta di pubblicazione - Condoglianze', #subject
            inputImmagine1, #message 
            inputEmail, # from email
            ['XXX@gmail.com'], # to email
        )

        return render(request, 'publication.html', {'inputImmagine1': inputImmagine1})

    else:
        return render(request, 'publication.html', {})
Safwan Samsudeen
  • 1,645
  • 1
  • 10
  • 25
Simone
  • 21
  • 4

1 Answers1

0

You can use the EmailMessage class to attach files

from django.core.mail import EmailMessage

email = EmailMessage(
    'Hello',
    'Body goes here',
    'from@example.com',
    ['to1@example.com', 'to2@example.com'],
)
email.attach_file('/logo.png')
email.send()

Check the docs for sending emails.

Edit: For handling files uploaded in the frontend, check the Django docs for file uploads.

Safwan Samsudeen
  • 1,645
  • 1
  • 10
  • 25
  • Thank you Sir, what about in the case I ask the users to load their image through a form and I want the system to send to my corporate mail the attachment as displayed on my code above? – Simone Nov 01 '20 at 10:07