title: MailKit: How to download all attachments locally from a MimeMessage
body: <p>I have looked at other examples online, but I am unable to figure out how to download and store ALL the attachments from a MimeMessage object.
  I did look into the WriteTo(), but I could not get it to work.
  Also wondering whether attachments will be saved according to the original file name, and type inside the email.
  Here is what I have so far:</p>
  
  <pre><code>using (var client = new ImapClient())
  {
      client.Connect(Constant.GoogleImapHost, Constant.ImapPort, SecureSocketOptions.SslOnConnect);
      client.AuthenticationMechanisms.Remove(Constant.GoogleOAuth);
      client.Authenticate(Constant.GoogleUserName, Constant.GenericPassword);
  
      if (client.IsConnected == true)
      {
          FolderAccess inboxAccess = client.Inbox.Open(FolderAccess.ReadWrite);
          IMailFolder inboxFolder = client.GetFolder(Constant.InboxFolder);
          IList&lt;UniqueId&gt; uids = client.Inbox.Search(SearchQuery.All);
  
          if (inboxFolder != null &amp; inboxFolder.Unread &gt; 0)
          {
              foreach (UniqueId msgId in uids)
              {
                  MimeMessage message = inboxFolder.GetMessage(msgId);
  
                  foreach (MimeEntity attachment in message.Attachments)
                  {
                      //need to save all the attachments locally
                  }
              }
          }
      }
  }
  </code></pre>