I need to iterate over all the mail into a GMAIL inbox. Also I need to download all the attachments for each mail (some mails have 4-5 attachments). I found some helps here : https://stackoverflow.com/a/27556667/8996442
def save_attachments(self, msg, download_folder="/tmp"):
for part in msg.walk():
if part.get_content_maintype() == 'multipart':
continue
if part.get('Content-Disposition') is None:
continue
filename = part.get_filename()
print(filename)
att_path = os.path.join(download_folder, filename)
if not os.path.isfile(att_path):
fp = open(att_path, 'wb')
fp.write(part.get_payload(decode=True))
fp.close()
return att_path
But, it download only one attachment per e-mail (but the author of the post mention that norammly it download all, no?).
The print(filename)
show me only one attachment
Any idea why ?