title: How to send waysiprint pdf by mail
body: <p>I'm trying to generate a pdf file from an HTML template using Weasyprint python package and I need to send it via email using.</p>
  
  <p>Here's what i have tried:</p>
  
  <p>views.py :</p>
  
  <pre><code>       user_info = {
              "name": 'nadjib',
          }
          html_string = render_to_string('Proformas/command.html')
  
          html = HTML(string=html_string,base_url=request.build_absolute_uri())
          # html.write_pdf(target='/tmp/mypdf.pdf');
  
          fs = FileSystemStorage('/tmp')
          with fs.open('mypdf.pdf') as pdf:
            response = HttpResponse(pdf, content_type='application/pdf')
            response['Content-Disposition'] =  'filename="Commande.pdf"'
            pdf = weasyprint.HTML(string=html_string, base_url=request.build_absolute_uri()).write_pdf(
                stylesheets=[weasyprint.CSS(string='body { font-family: serif}')])
            to_emails = ['nadjzdz@gmail.com']
            subject = "SH INFOR FACTURE"
            email = EmailMessage(subject, body=pdf, from_email='attaazd@gmail.com', to=to_emails)
            email.attach("Commande".format(user_info['name']) + '.pdf', pdf, "application/pdf")
            email.content_subtype = "pdf"  # Main content is now text/html
            email.encoding = 'us-ascii'
            email.send()
          return response
  
  </code></pre>
  
  <p>the pdf is rendered successfully but not sent by mail ?</p>