Example #1
0
        public void ReadLabels()
        {
            var service = new GmailService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me");

            IList <Google.Apis.Gmail.v1.Data.Label> labels = request.Execute().Labels;

            System.Diagnostics.Debug.WriteLine("Labels:");
            if (labels != null && labels.Count > 0)
            {
                foreach (var labelItem in labels)
                {
                    System.Diagnostics.Debug.WriteLine(labelItem.Name);
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("No labels found.");
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            UserCredential credential;

            using (var stream =
                       new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = "token.json";
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // 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");
            UsersResource.MessagesResource.ListRequest messagesRequest = service.Users.Messages.List("me");

            // List labels.
            IList <Label> labels = request.Execute().Labels;

            Console.WriteLine("Labels:");
            if (labels != null && labels.Count > 0)
            {
                foreach (var labelItem in labels)
                {
                    Console.WriteLine("{0}", labelItem.Name);
                }
            }
            else
            {
                Console.WriteLine("No labels found.");
            }

            IList <Message> messages = messagesRequest.Execute().Messages;

            Console.WriteLine("Messages:");
            if (messages != null && messages.Count > 0)
            {
                foreach (var message in messages)
                {
                    Console.WriteLine("{0}", message.Id);
                }
            }
            else
            {
                Console.WriteLine("No messages found.");
            }
            Console.Read();
        }
Example #3
0
        public static void ConectarAPI(YanapayEmail email)
        {
            UserCredential credential;

            using (var stream =
                       new FileStream("C:/inetpub/wwwroot/TableSoftEmail/credentials.json", FileMode.Open, FileAccess.Read))
            {
                // The file token.json stores the user's access and refresh tokens, and is created
                // automatically when the authorization flow completes for the first time.
                string credPath = "C:/pixies/token.json";
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // 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");

            SendEmail(email, service);
        }
Example #4
0
        public async void ReadAllMails(string label)
        {
            var service = new GmailService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = _credentials,
                ApplicationName       = ApplicationName,
            });

            // Define parameters of request.
            UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("fnb");

            // List labels.
            IList <Label> labels = request.Execute().Labels;

            Console.WriteLine("Labels:");
            if (labels != null && labels.Count > 0)
            {
                foreach (var labelItem in labels)
                {
                    Console.WriteLine("{0}", labelItem.Name);
                }
            }
            else
            {
                Console.WriteLine("No labels found.");
            }
            Console.Read();
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        public override List <Entities.Message> ReadMessages(int page = 1)
        {
            //var url = "https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest";
            //var response = ReadApi(url);

            //Logger.Info(response);

            var service = new GmailService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = GetCredential(),
                ApplicationName       = ApplicationName,
            });

            // Define parameters of request.
            UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me");

            // List labels.
            IList <Label> labels = request.Execute().Labels;

            Logger.Info("Labels:");
            if (labels != null && labels.Count > 0)
            {
                foreach (var labelItem in labels)
                {
                    Logger.Info($"{labelItem.Name}");
                }
            }
            else
            {
                Logger.Info("No labels found.");
            }

            return(new List <Entities.Message>());
        }
Example #6
0
        static void Main(string[] args)
        {
            UserCredential credential;

            using (var stream =
                       new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);
                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);
            }

            // Create Gmail API service.
            var service = new GmailService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me");
            var res = service.Users.Messages;

            ListLabels(request);
            ListMessages(service, "me", "in after:2016/05/15");
        }
Example #7
0
        public static bool SendMail()
        {
            try
            {
                // Operaciones
                UserCredential credential;

                using (var stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
                {
                    string credPath = "token.json";
                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.Load(stream).Secrets,
                        Scopes,
                        "user",
                        CancellationToken.None,
                        new FileDataStore(credPath, true)).Result;
                }

                // Creamos un servicio de GMAIL.
                var service = new GmailService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = ApplicationName,
                });

                // Definimos parametros de la solicitud.
                UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me");

                //UsersResource.LabelsResource.ListRequest request =
                string plainText = "To: [email protected]\r\n" +
                                   "Subject: subject Test\r\n" +
                                   "Content-Type: text/html; charset=us-ascii\r\n\r\n" +
                                   "<h1>Body Test </h1>";

                var newMsg = new Google.Apis.Gmail.v1.Data.Message();
                newMsg.Raw = EmailHelper.Base64UrlEncode(plainText.ToString());
                service.Users.Messages.Send(newMsg, "me").Execute();

                // ??
                //IList<Label> labels = request.Execute().Labels;

                //if (labels != null && labels.Count > 0)
                //{
                //    foreach (var labelItem in labels)
                //        File.AppendAllText("salidaLabels.txt", labelItem.Name);
                //}
                //else
                //{
                //    throw new ApplicationException("No labels found.");
                //}


                return(true);
            }
            catch (Exception ex)
            {
                // LOGGER
                return(false);
            }
        }
Example #8
0
        public static List <string> GetLabels(GmailService service)
        {
            UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me");
            IList <Label> labels = request.Execute().Labels;

            return(labels.Select(l => l.Name).ToList());
        }
Example #9
0
        public IActionResult Setup()
        {
            UserCredential credential = GetCredentials();

            _logger.LogInformation($"Got credentials {credential?.Token?.AccessToken}");

            // 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("*****@*****.**");
            _logger.LogInformation($"Got request {request?.MethodName}");

            // List labels.
            IList <Label> labels = request.Execute().Labels;

            _logger.LogInformation("Labels:");
            if (labels != null && labels.Count > 0)
            {
                foreach (var labelItem in labels)
                {
                    _logger.LogInformation("{0}", labelItem.Name);
                }
            }
            else
            {
                _logger.LogInformation("No labels found.");
            }
            return(Ok());
        }
        public GmailService GetService(string userName, string password)
        {
            UserCredential credential;

            string[] Scopes          = { GmailService.Scope.GmailReadonly };
            string   ApplicationName = "Gmail API .NET Quickstart";

            using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                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;
            }


            var service = new GmailService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me");
            return(service);
        }
Example #11
0
        static void Main(string[] args)
        {
            UserCredential credential;

            using (var stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
            {
                // The file token.json stores the user's access and refresh tokens, and is created
                // automatically when the authorization flow completes for the first time.
                string credPath = "token.json";
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            while (true)
            {
                // Create Gmail API service.
                var service = new GmailService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = ApplicationName,
                });

                // Define parameters of request.
                // List labels.
                UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me");
                var labels = request.Execute().Labels.Where(l => l.Name.ToLower() == "inbox").Select(lp => service.Users.Labels.Get("me", lp.Id).Execute());
                foreach (var label in labels.OrderByDescending(l => l.MessagesUnread))
                {
                    Console.WriteLine($"Status: {label.Name} {label.MessagesUnread}/{label.MessagesTotal}");

                    var r = service.Users.Messages.List("me");
                    r.Q = "in:inbox is:unread";
                    var mails = r.Execute().Messages?.Select(mp => service.Users.Messages.Get("me", mp.Id).Execute());
                    if (mails == null)
                    {
                        continue;
                    }

                    foreach (var mail in mails)
                    {
                        var from    = mail.Payload.Headers.SingleOrDefault(mph => mph.Name == "From").Value;
                        var subject = mail.Payload.Headers.SingleOrDefault(mph => mph.Name == "Subject").Value;

                        DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(mail.InternalDate ?? 0);

                        Console.WriteLine($" - [{dateTimeOffset.LocalDateTime}] From: {from}, Subject: {subject}{(mail.Snippet.Length > 0 ? ", Snippit: " + mail.Snippet : "")}");
                    }

                    Console.Beep();
                }

                Task.Delay(1000 * 30).Wait();
            }
        }
        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();
        }
Example #13
0
        public IList <Label> ReadLabels()
        {
            GmailService service = CreateService();

            UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me");

            return(request.Execute().Labels);
        }
Example #14
0
        static void Main(string[] args)
        {
            UserCredential credential;

            using (var stream =
                       new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);
                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);
            }

            // Create Gmail API service.
            try
            {
                var service = new GmailService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName       = ApplicationName,
                });

                // Define parameters of request.
                UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me");//userId
                Message l = MyClass.GetMessage(service, "me", "159ff2348b11ae36");

                Console.WriteLine("{0}", l.Snippet);

                // List labels.
                IList <Label> labels = request.Execute().Labels;
                Console.WriteLine("Labels:");
                if (labels != null && labels.Count > 0)
                {
                    foreach (var labelItem in labels)
                    {
                        Console.WriteLine("{0}", labelItem.Name);
                    }
                }
                else
                {
                    Console.WriteLine("No labels found.");
                }
                Console.Read();
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e);
                Console.ReadKey();
            }
        }
        static void Main(string[] args)
        {
            try
            {
                List <Message>            Messages             = null;
                List <GmailMessageObject> GmailXTrelloMessages = new List <GmailMessageObject>();
                while (true)
                {
                    UserCredential credential;
                    using (FileStream stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
                    {
                        string credPath = "token.json";
                        credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                            GoogleClientSecrets.Load(stream).Secrets,
                            Scopes,
                            "user",
                            CancellationToken.None,
                            new FileDataStore(credPath, true)).Result;
                        Console.WriteLine("Credential file saved to: " + credPath);
                    }

                    GmailService service = new GmailService(new BaseClientService.Initializer()
                    {
                        HttpClientInitializer = credential,
                        ApplicationName       = ApplicationName,
                    });


                    GmailUtilities.MessagesList             = Messages;
                    GmailUtilities.GmailXTrelloMessagesList = GmailXTrelloMessages;
                    GmailUtilities.ReadMails(service, "*****@*****.**");
                    Messages             = GmailUtilities.MessagesList;
                    GmailXTrelloMessages = GmailUtilities.GmailXTrelloMessagesList;

                    UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me");
                    IList <Label> labels = request.Execute().Labels;
                    Console.WriteLine("Labels:");
                    if (labels != null && labels.Count > 0)
                    {
                        foreach (var labelItem in labels)
                        {
                            Console.WriteLine("{0}", labelItem.Name);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No labels found.");
                    }
                }
            }
            catch (Exception error)
            {
                Tools.LogWriter.WriteLog(error.Message);
            }
            Task.Delay(1000);
        }
Example #16
0
        public IList <Label> GetLabelList()
        {
            // Define parameters of request.
            UsersResource.LabelsResource.ListRequest request = _service.Users.Labels.List("me");

            // List labels.
            IList <Label> labels = request.Execute().Labels;

            return(labels);
        }
Example #17
0
        static void Main(string[] args)
        {
            var secrets = new ClientSecrets
            {
                ClientId     = ConfigurationSettings.AppSettings["GMailClientId"],
                ClientSecret = ConfigurationSettings.AppSettings["GMailClientSecret"]
            };

            var token = new TokenResponse {
                RefreshToken = ConfigurationSettings.AppSettings["GmailRefreshToken"]
            };
            var credential = new UserCredential(new GoogleAuthorizationCodeFlow(
                                                    new GoogleAuthorizationCodeFlow.Initializer
            {
                ClientSecrets = secrets
            }), "user", token);

            //Console.WriteLine("Credential file saved to: " + credPath);


            // Create Gmail API service.
            var gmailService = new GmailService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });



            GetMessage(gmailService);

            // Define parameters of request.
            UsersResource.LabelsResource.ListRequest request = gmailService.Users.Labels.List("me");

            // List labels.
            IList <Label> labels = request.Execute().Labels;

            Console.WriteLine("Labels:");
            if (labels != null && labels.Count > 0)
            {
                foreach (var labelItem in labels)
                {
                    Console.WriteLine("{0}", labelItem.Name);
                }
            }
            else
            {
                Console.WriteLine("No labels found.");
            }



            Console.ReadKey();
        }
Example #18
0
        public IEnumerable <string> ReadGmail()
        {
            // If modifying these scopes, delete your previously saved credentials
            // at ~/.credentials/gmail-dotnet-quickstart.json

            UserCredential credential;

            using (var stream =
                       new MemoryStream(Encoding.UTF8.GetBytes("")))
            {
                string credPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);
                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);
            }

            // 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");

            // List labels.
            var labels = request.Execute().Labels;

            return(labels.Select(x => x.Name));
            //Console.WriteLine("Labels:");
            //if (labels != null && labels.Count > 0)
            //{
            //    foreach (var labelItem in labels)
            //    {
            //        Console.WriteLine("{0}", labelItem.Name);
            //    }
            //}
            //else
            //{
            //    Console.WriteLine("No labels found.");
            //}
            //Console.Read();
        }
Example #19
0
        public Gmail()
        {
            UserCredential credential;

            display("looks like we are inside");
            using (var stream =
                       new FileStream(AppDomain.CurrentDomain.BaseDirectory + "UTIL/credentials.json", FileMode.Open, FileAccess.ReadWrite))
            {
                display("file stream created. path: " + AppDomain.CurrentDomain.BaseDirectory + "UTIL/credentials.json");
                // The file token.json stores the user's access and refresh tokens, and is created
                // automatically when the authorization flow completes for the first time.
                string credPath = "token.json";
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // Create Gmail API service.
            var service = new GmailService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            display("api service created");
            // Define parameters of request.
            UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me");

            // List labels.
            IList <Label> labels = request.Execute().Labels;

            Console.WriteLine("Labels:");
            if (labels != null && labels.Count > 0)
            {
                foreach (var labelItem in labels)
                {
                    Console.WriteLine("{0}", labelItem.Name);
                }
            }
            else
            {
                Console.WriteLine("No labels found.");
            }
            Console.Read();
            display("ya everything was read.");
        }
Example #20
0
        private async Task <ListMessagesResponse> ListMessages(string label)
        {
            var service = await Service();

            // Define parameters of request.
            UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me");

            var allListMails = service.Users.Messages.List("*****@*****.**");

            allListMails.LabelIds         = label; // take data only from inbox
            allListMails.IncludeSpamTrash = false; // not take data from spam

            return(await allListMails.ExecuteAsync());
        }
Example #21
0
        private List <Label> GetLabels()
        {
            UserCredential credential;

            using (var stream =
                       new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
            {
                // The file token.json stores the user's access and refresh tokens, and is created
                // automatically when the authorization flow completes for the first time.
                string credPath = "token.json";
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // 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");

            // List labels.
            IList <Label> labels = request.Execute().Labels;

            var result = new List <Label>();

            Console.WriteLine("Labels:");
            if (labels != null && labels.Count > 0)
            {
                foreach (var labelItem in labels)
                {
                    result.Add(labelItem);
                    Console.WriteLine("{0}", labelItem.Name);
                }
            }
            else
            {
                Console.WriteLine("No labels found.");
            }

            return(result);
        }
        static void Main(string[] args)
        {
            try
            {
                UserCredential credential;
                // Load client secrets.
                using (var stream =
                           new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
                {
                    /* The file token.json stores the user's access and refresh tokens, and is created
                     * automatically when the authorization flow completes for the first time. */
                    string credPath = "token.json";
                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.FromStream(stream).Secrets,
                        Scopes,
                        "user",
                        CancellationToken.None,
                        new FileDataStore(credPath, true)).Result;
                    Console.WriteLine("Credential file saved to: " + credPath);
                }

                // 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");

                // List labels.
                IList <Label> labels = request.Execute().Labels;
                Console.WriteLine("Labels:");
                if (labels == null || labels.Count == 0)
                {
                    Console.WriteLine("No labels found.");
                    return;
                }
                foreach (var labelItem in labels)
                {
                    Console.WriteLine("{0}", labelItem.Name);
                }
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }
        }
        public async Task <IEnumerable <CurrentMessage> > GetRangeMessagesAsync(int skip, int take)
        {
            GmailService service = CreateGmailService();

            // Define parameters of request.
            UsersResource.LabelsResource.ListRequest labelsRequest = service.Users.Labels.List("me");
            List <Message> messages = await ListMessages(service, "me", "");

            MessagesCount = messages.Count();
            messages      = messages.Skip(skip * take).Take(take).ToList();

            List <CurrentMessage> messagesInfo = await GetMessagesPartsAsync(messages, service);

            return(messagesInfo);
        }
Example #24
0
        static void Main(string[] args)
        {
            // Create Gmail API service.
            var service = GetService();

            // Define parameters of request.
            UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me");

            var msgs = ListMessages(service, "me", "from:[email protected]");

            Console.WriteLine(string.Format("Processing {0} emails.", msgs.Count));

            for (int i = msgs.Count - 1; i > 0; --i) //processing in reverse so newest are done last.
            {
                var emailBodyString = DecodeEmailBody(GetMessage(service, "me", msgs[i].Id));

                try
                {
                    var entity = ParseEmailToZillowEntity(emailBodyString);

                    if (entity.zpid > 0)
                    {
                        // Upload home details to local database for easy querying from webpage.
                        UpsertZillowEntity(entity);
                    }
                    else
                    {
                        // Unable to find property so log email for reference (debug, error, info, ect.)
                        LogEmail(emailBodyString);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                //******* Only send message for especially good deals? Send TXT MSG??
                //SendMessage(service, "me", CreateEmail("test results"));
                Console.Write("|");

                // Finally clean up email
                DeleteMessage(service, "me", msgs[i].Id);
            }

            Console.WriteLine();
            Console.WriteLine("Complete. (Press any key to close)");
            Console.ReadKey();
        }
Example #25
0
        public GetInformationsViewModel GetInformations()
        {
            string         path = HttpContext.Current.Server.MapPath("~/App_Data/client_secret.json");
            UserCredential credential;

            using (var stream =
                       new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);
                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;
            }
            // 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");
            // List labels.
            IList <Label> labels = request.Execute().Labels;

            UsersResource.MessagesResource.ListRequest requestMessages = service.Users.Messages.List("me");
            IList <Message> messages     = requestMessages.Execute().Messages;
            List <Message>  messagesFull = new List <Message>();

            foreach (var message in messages)
            {
                var messageFull = service.Users.Messages.Get("me", message.Id).Execute();
                messagesFull.Add(messageFull);
            }


            var getInformationsViewModel = new GetInformationsViewModel();

            getInformationsViewModel.Labels   = labels;
            getInformationsViewModel.Messages = messagesFull;
            return(getInformationsViewModel);
        }
Example #26
0
        static void Main(string[] args)
        {
            UserCredential credential;

            using (var stream =
                       new FileStream(@"D:\Javra\GitProject\QuotAppDev\DevBranch\EncryptionTool\EncryptTool\ReadEmail\client_secret.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);
                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);
            }

            // 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");

            // List labels.
            IList <Label> labels = request.Execute().Labels;

            Console.WriteLine("Labels:");
            if (labels != null && labels.Count > 0)
            {
                foreach (var labelItem in labels)
                {
                    Console.WriteLine("{0}", labelItem.Name);
                }
            }
            else
            {
                Console.WriteLine("No labels found.");
            }
            Console.Read();
        }
Example #27
0
        static void gouse()
        {
            UserCredential credential;

            using (var stream =
                       new FileStream("C:\\Users\\MinzaMushtaq3\\Documents\\Acclaim_modern\\Acclaim_modern\\Credentials\\client_secret_502662755669-89l9oe45edmvaoqjrj9745jpjgd48qpr.apps.googleusercontent.com.json", FileMode.Open, FileAccess.Read))
            {
                // The file token.json stores the user's access and refresh tokens, and is created
                // automatically when the authorization flow completes for the first time.
                string credPath = "token.json";
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // 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");

            // List labels.
            IList <Label> labels = request.Execute().Labels;

            Console.WriteLine("Labels:");
            if (labels != null && labels.Count > 0)
            {
                foreach (var labelItem in labels)
                {
                    Console.WriteLine("{0}", labelItem.Name);
                }
            }
            else
            {
                Console.WriteLine("No labels found.");
            }
            Console.Read();
        }
Example #28
0
        public static void ListLabels(UsersResource.LabelsResource.ListRequest request)
        {
            IList <Label> labels = request.Execute().Labels;

            Console.WriteLine("Labels:");
            if (labels != null && labels.Count > 0)
            {
                foreach (var labelItem in labels)
                {
                    Console.WriteLine("{0}", labelItem.Name);
                }
            }
            else
            {
                Console.WriteLine("No labels found.");
            }
        }
Example #29
0
        private string ListLabels(UsersResource.LabelsResource.ListRequest request)
        {
            var           labels = request.Execute().Labels;
            StringBuilder text   = new StringBuilder("Labels : ");

            if (labels != null && labels.Count > 0)
            {
                foreach (var label in labels)
                {
                    text.Append($" {label}\n");
                }
            }
            else
            {
                text.Append("None!");
            }
            return(text.ToString());
        }
        public List <string> GetLabels()
        {
            var service = GetGmailService();

            // Define parameters of request.
            UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List(userId);
            IList <Label> gLabels = request.Execute().Labels;
            List <string> labels  = new List <string>();

            foreach (var label in gLabels)
            {
                labels.Add(label.Name);
            }
            if (labels != null && labels.Count > 0)
            {
                return(labels);
            }
            return(null);
        }