title: How to get csv attachment from email and save it
body: <p>I am trying to get the attachment from an email and save it to a specific folder with the original file name. The email is very basic and does not have much to it other than the attachment. The file is a csv file and there will be only one per email. This is what I have so far, but I'm new to this and am not sure how to proceed. This is using Outlook if that helps. Any help is appreciated.</p>
  
  <pre><code>import imaplib
  import email
  
  
  mail=imaplib.IMAP4('mailserver.com')
  mail.login("username", "password")
  mail.select("DetReport")
  
  typ, msgs = mail.uid('Search', None, '(SUBJECT "Detection")')
  msgs = msgs[0].split()
  
  for emailid in msgs:
      resp, data = mail.fetch(emailid, "(RFC822)")
      email_body = data[0][1] 
      m = email.message_from_string(email_body)
  
  
      message=m.get_content_maintype()
  </code></pre>
  
  <p>FYI, when I run the <code>message=m.get_content_maintype()</code> it says it is text.</p>