get sender name and mailing address when downloading attachments #1144
-
How to get sender name and mailing address when downloading attachments. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
from exchangelib import Message
Message.FIELDS will show you all fields available on messages. You're probably looking for the |
Beta Was this translation helpful? Give feedback.
-
Thanks for the answer. I also wanted to ask how you can download attachments only from new letters, right now I have it set up by reverse sorting by the date of the letter and if there are no new letters, then the last one is always downloaded, is it possible by the dates of the letters, i.e. refer only to the new letter. |
Beta Was this translation helpful? Give feedback.
-
I chose option 3, but there were difficulties. #file_datetime_received = None
with open(path_attch +"\datetime_received.txt") as file:
file_datetime_received = file.read()
#print(file_datetime_received)
for item in account.inbox.all().filter(q).order_by('-datetime_received')[:1]:
if str(item.datetime_received) != file_datetime_received: # check that the new letter has a greater date than the previous one
for attachment in item.attachments:
if isinstance(attachment, FileAttachment):
local_path = os.path.join(path_attch, attachment.name)
with open(local_path, 'wb') as f:
f.write(attachment.content)
print('Сохраняем вложение в ', local_path)
else:
break |
Beta Was this translation helpful? Give feedback.
It's a lot easier to use the stored datetime value if you convert it to a datetime when you read it, instead of using it as a string in your condition: