static void Main(string[] args) { IAttach attach = new AttachController(); OutlookController outlookController = new OutlookController(attach); outlookController.Read(); throw new Exception(""); // IGmail gmail = new GmailController(attach); UserCredential credential; using (var stream = new FileStream(@pathinit + @"\client_secret.json", FileMode.Open, FileAccess.Read)) { try { // string credPath = System.Environment.GetFolderPath( //System.Environment.SpecialFolder.Personal); string credPath = pathinit; credPath = Path.Combine(credPath, ".credentials/gmail-dotnet-quickstart.json"); credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; Console.WriteLine("Credential file saved to: " + credPath); } catch (Exception ex) { Console.Write(ex); throw; } } // Create Gmail API service. var service = new GmailService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = ApplicationName, }); // Define parameters of request. UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me"); // start read mail //UsersResource.MessagesResource.ListRequest requestMessage = service.Users.Messages.List("me"); //IList<Message> listMessage = requestMessage.Execute().Messages; IList <Message> listMessage = gmail.ListMessages(service, "me", "has:attachment"); foreach (var item in listMessage) { var res = gmail.GetMessage(service, "me", item.Id); gmail.GetAttachments(service, "me", res.Id); } Console.Read(); }