title: Send attached file with Mailgun using python
body: <p>I'm trying to send an email with an attached file with the Mailgun API using requests.post.</p>
  
  <p>In their documentation they alert that <strong>you must use</strong> multipart/form-data encoding when sending attachments, I'm trying this:</p>
  
  <pre><code>import requests
  MAILGUN_URL = 'https://api.mailgun.net/v3/sandbox4f...'
  MAILGUN_KEY = 'key-f16f497...'
  
  
  def mailgun(file_url):
      """Send an email using MailGun"""
  
      f = open(file_url, 'rb')
  
      r = requests.post(
          MAILGUN_URL,
          auth=("api", MAILGUN_KEY),
          data={
              "subject": "My subject",
              "from": "my_email@gmail.com",
              "to": "to_you@gmail.com",
              "text": "The text",
              "html": "The&lt;br&gt;html",
              "attachment": f
          },
          headers={'Content-type': 'multipart/form-data;'},
      )
  
      f.close()
  
      return r
  
  
  mailgun("/tmp/my-file.xlsx")
  </code></pre>
  
  <p>I've defined the header to be sure that the content type is <strong>multipart/form-data</strong>, but when I run the code, I get a 400 status with reason: Bad Request</p>
  
  <p>What's wrong? <strong>I need be sure that i'm using multipart/form-data</strong> and I'm using correctly the <strong>attachment</strong> parameter</p>