title: Powershell - Download Attachment from Gmail
body: <p>So this is what I did so far:</p>
  
  <pre><code>$dll = 'C:\Users\xxxx\Desktop\v4.6\imapx.dll'
  [Reflection.Assembly]::LoadFile($dll)
  
  $Username = "xxxxxx"
  $Password = "yyyyyy"
  
  
  # Initialize the IMAP client
  $client = New-Object ImapX.ImapClient
  
  ###set the fetching mode to retrieve the part of message you want to retrieve, 
  ###the less the better
  $client.Behavior.MessageFetchMode = "Full"
  $client.Host = "imap.gmail.com"
  $client.Port = 993
  $client.UseSsl = $true
  $client.Connect()
  $client.Login($Username, $Password)
  
  # Get folder/label object containing emails you want to read from
  $res = $client.folders| where { $_.path -eq 'Inbox' }
  
  
  # Search email threads inside the subfolder
  $numberOfMessagesLimit = 10
  $messages = $res.search("All", $client.Behavior.MessageFetchMode, $numberOfMessagesLimit)
  
  # Display the messages in a formatted table
  $messages | ft *
  
  
  foreach($m in $messages){
  $m.Subject
  foreach($r in $m.Attachments){
  $r | Out-File C:\Users\xxxx\Desktop\x\log.txt
      }
   }
  </code></pre>
  
  <p>I got the information about the attachment file in the log.txt.</p>
  
  <pre><code>ContentId               : 
  FileData                : {120, 120, 120, 120}
  FileName                : test.txt
  Downloaded              : True
  ContentType             : text/plain; name=test.txt; charset=US-ASCII
  ContentTransferEncoding : Base64
  FileSize                : 4
  </code></pre>
  
  <p>Ok, very nice....but the question now, <strong><em>how can I download the attachment itself??!</em></strong> :D </p>