I am trying to get an attachment from email and save it in a specific folder with the original file name. Email is very simple and has nothing but an app. The file is a csv file, and for each letter there will be only one. This is what I still have, but I'm new to this and donβt know how to proceed. This will help Outlook if it 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 message=m.get_content_maintype() , it says that it is text.
source share