Download all attachments received in the past 30 days
<p>Below is my code.</p>

<pre><code>import win32com.client,datetime

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6).Folders('Paper &amp; CD')
messages = inbox.Items
date_now = datetime.datetime.now().date()
date_before = (datetime.datetime.now() + datetime.timedelta(-30)).date()
for msg in messages:        
    for att in msg.Attachments:
        if att.FileName == 'list.csv': 
            att.SaveAsFile('C:\\My\\temp\\' + msg.subject + att.FileName)
        att.SaveAsFile('C:\\My\\temp\\' + att.FileName)
</code></pre>

<p>It downloads all attachments from the particular folder.</p>

<p>I need to download only attachments not more than 30 days old.</p>

<p>I tried with <code>msg.LastModificationTime</code> but it gives last modified time of mail.</p>

<p>I want to know the received date for each mail so I can compare it with current date.</p>

<p>Use <code>Items.Restrict</code> or <code>Items.Find/FindNext</code> with a restriction based on the <code>ReceivedTime</code> property.</p>

python outlook