title: Python Sendmail with Attachment?
body: <p>I am programming with python. I already have a function that sends mails with attachments, but the problem is that it takes the message and puts it as an attachment. I need that it respects the message as message and the attachment as attachment. I have investigated and I found that has to do with MIME Multipart "MIXED" but i don't know how to add or change this to my actual functions.</p>
  
  <p>Here is the python code of the function I am using:</p>
  
  <pre><code>def enviarCorreo(fromaddr, toaddr, file):
      msg = MIMEMultipart('mixed')
      msg['From'] = fromaddr
      msg['To'] = toaddr
      msg['Subject'] = 'asunto'
      #adjunto
      adjunto = MIMEBase('application', "octet-stream")
      adjunto.set_payload(open(file, "rb").read())
      encode_base64(adjunto)
      adjunto.add_header('Content-Disposition', 'attachment; filename= "%s"' % file)
      msg.attach(adjunto)
      #enviar
      server = smtplib.SMTP('localhost')
      server.set_debuglevel(1)
      server.sendmail(fromaddr, toaddr, msg.as_string())
      server.quit()
      return
  </code></pre>