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.
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()
FYI, when I run the message=m.get_content_maintype()
it says it is text.