You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Nevermind, I got it!
This is an example to download only Excel files, from unread emails, 7 or less days old:
from simplegmail import Gmail
from simplegmail.query import construct_query
gmail = Gmail()
query_params = {
"newer_than": (7, "day"),
"unread": True,
"spec_attachment":'xlsx', #PDF or whatever you want
}
messages = gmail.get_messages(query=construct_query(query_params))
try:
message = messages[0]
if message.attachments:
for attm in message.attachments:
print('File: ' + attm.filename)
attm.save() # downloads and saves each attachment under it's stored
# filename. You can download without saving with `attm.download()`
except:
print("Error, probably no specified files found")
exit()
Your scripts are great! I wonder how to dowload ony one type of attachments, for example PDFs or Excel files.
The text was updated successfully, but these errors were encountered: