def envoiemail(request): courrier = Courrier.objects.filter(mention=“ETUDE ET COMPTE…
- User
def envoi_email(request): courrier = Courrier.objects.filter(mention=“ETUDE ET COMPTE RENDU”, is_active=True) count_courrier = courrier.count()
if request.method == ‘POST’: name = request.POST.get(‘name’) email = request.POST.get(‘email’)
phone = request.POST.get(‘phone’)
message = request.POST.get(‘message’) form_data = { ‘name’:name, ‘email’:email,
‘phone’:phone,
‘message’:message, } recipient_list = email
message = ‘’‘
From:\n\t\t{}\n
Message:\n\t\t{}\n
Email:\n\t\t{}\n
‘’’.format(form_data[‘name’], form_data[‘message’], form_data[‘email’])
send_mail(‘You got a mail!’, message, ‘’, [‘<PRESIDIO_ANONYMIZED_EMAIL_ADDRESS>’]) # TODO: enter your email address
send_mail(name, message, email, [recipient_list])
return render(request,‘envoi_email.html’, {“courrier”: courrier, “count_courrier”: count_courrier})
i need to add atachment when i send email
- Assistant
To add an attachment to the email, you need to use the
EmailMessageclass from the Djangoemailmodule. First, you need to handle the file upload from the HTML form and then attach the file to the email.