title: How To save all the attachments from the mail in the outlook without specifying the attachment name
body: <p>I am new to python. I am trying to save all the attachment from the email <strong>without specifying the attachment name</strong> from the outlook.</p>
  <p>We need to download the attachment with the subject name.</p>
  <p>because attachment can come in any name and also i need to download the attachment only for past 2 days.</p>
  <p>Could anyone help me. Below is my code</p>
  <pre><code>    from win32com.client import Dispatch
  import time
  import datetime
  import re
  outlook = Dispatch(&quot;Outlook.Application&quot;).GetNamespace(&quot;MAPI&quot;)
  inbox = outlook.GetDefaultFolder(&quot;6&quot;)
  all_inbox = inbox.Items
  val_date = datetime.date.today()
   
  sub_today = 'test4'
  att_today = '20201018_2.xlsx'    
  #att_today = re.match(regex_, )
  for msg in all_inbox:
      if msg.Subject.find(sub_today) != -1 and msg.SentOn.date() == val_date:
          break
  
  for att in msg.Attachments:
      if att.FileName == att_today:
          print(att_today)
          break
  
  try:
      print(att.FileName)
      #att.SaveAsFile(&quot;C:/Users/Shwettha/Downloads/attachment/&quot;+ att.FileName)
      att.SaveAsFile(os.path.join(&quot;D:\Script\Monitoring&quot;,att.FileName))
      print(&quot;SUCCESSFUL&quot;,&quot;Attachments Downloaded&quot;)
  except:
      print(&quot;ERROR&quot;,&quot;Attachment Download Failed&quot;)   
  </code></pre>