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(); }
/// <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>()); }
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 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()); }
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(); }
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."); } }
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(); } }
public IList <Label> ReadLabels() { GmailService service = CreateService(); UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me"); return(request.Execute().Labels); }
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); }
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); }
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(); }
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(); }
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); }
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."); }
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 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); }
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(); }
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(); }
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."); } }
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); }
public static void PrintLabels() { var service = Connection.GetGmailService(); // List labels. 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(labelItem.Name + " Message list visibility: " + labelItem.MessageListVisibility + " Messages Total: " + labelItem.MessagesTotal.HasValue + "Unread: " + labelItem.MessagesUnread.HasValue); } } else { Console.WriteLine("No labels found."); } }
// API protected void GmailAPI(object sender, EventArgs e) { String credPath = System.Web.HttpContext.Current.Server.MapPath("/App_Data/GmailAPI"); String uri = Request.Url.ToString(); String user_id = Util.GetUserId(); IAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow( new GoogleAuthorizationCodeFlow.Initializer { ClientSecrets = new ClientSecrets() { ClientId = "792417557967-mbt9n0cvnnlm01947sh1om351nd9quku.apps.googleusercontent.com", ClientSecret = "9lo8IshXhyIMy8_5jd6YoCNd" }, DataStore = new FileDataStore(credPath, true), Scopes = new String[] { GmailService.Scope.GmailReadonly } }); var code = Request["code"]; if (String.IsNullOrEmpty(code)) { AuthorizationCodeWebApp.AuthResult AuthResult = new AuthorizationCodeWebApp(flow, uri, uri).AuthorizeAsync(user_id, CancellationToken.None).Result; Util.Debug(AuthResult.RedirectUri); if (AuthResult.RedirectUri != null) { // Redirect the user to the authorization server. Page.ClientScript.RegisterStartupScript(this.GetType(), "OpenWindow", "window.open('" + AuthResult.RedirectUri + "','_newtab');", true); } else { // Create Gmail API service. GmailService service = new GmailService(new BaseClientService.Initializer() { HttpClientInitializer = AuthResult.Credential, ApplicationName = "My Project" }); // Define parameters of request. UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me"); // List labels. IList <Google.Apis.Gmail.v1.Data.Label> labels = request.Execute().Labels; Response.Write("Labels:"); if (labels != null && labels.Count > 0) { foreach (var labelItem in labels) { Response.Write(" " + labelItem.Name); } } else { Response.Write("No labels found."); } } } else { var token = flow.ExchangeCodeForTokenAsync(user_id, code, uri.Substring(0, uri.IndexOf("?")), CancellationToken.None).Result; // Extract the right state. var oauthState = AuthWebUtility.ExtracRedirectFromState(flow.DataStore, user_id, Request["state"]).Result; Page.ClientScript.RegisterStartupScript(this.GetType(), "OpenWindow", "window.open('" + oauthState + "','_newtab');", true); } }
public void Configuration(IAppBuilder app) { ConfigureAuth(app); 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, }); // 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."); } // service.Users // request. // Console.Read(); /* * GAlerts alert =new GAlerts("*****@*****.**","qpal1z11"); * alert.create("test", "en", "happens", "all", "best", "feed"); * * foreach(AlertItem item in alert.getList()) * { * * } */ IList <string> urls = new List <string>(); ListThreadsResponse threads = service.Users.Threads.List("me").Execute(); foreach (var thread in threads.Threads.ToList()) { if (thread.Snippet.Contains("Google student success")) { var threadDetails = service.Users.Threads.Get("me", thread.Id).Execute(); var msg = service.Users.Messages.Get("me", threadDetails.Messages[0].Id).Execute(); // byte[] encbuff = Encoding.UTF8.GetBytes(msg.Payload.Parts[0].Body.Data); // string decodedString = HttpServerUtility.UrlTokenEncode(encbuff); // byte[] decbuff = HttpServerUtility.UrlTokenDecode(msg.Payload.Parts[0].Body.Data); // decodedString = Encoding.UTF8.GetString(decbuff); string s = msg.Payload.Parts[0].Body.Data; string incoming = s .Replace('_', '/').Replace('-', '+'); switch (s.Length % 4) { case 2: incoming += "=="; break; case 3: incoming += "="; break; } byte[] bytes = Convert.FromBase64String(incoming); string originalText = Encoding.ASCII.GetString(bytes); var matchCollection = Regex.Matches(originalText, "(http|ftp|https)://([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?"); foreach (Match m in matchCollection) { if (!m.Value.Contains("https://www.google.com/alerts")) { urls.Add(m.Value); } } } } }
public MainWindow() { InitializeComponent(); UserCredential credential; using (var stream = new FileStream(@"C:\Users\Kaivaan\source\repos\WpfApp1\WpfApp1\client_id.json", FileMode.Open, FileAccess.Read)) { string credPath = System.Environment.GetFolderPath( System.Environment.SpecialFolder.Personal); credPath = System.IO.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; Console.WriteLine("Labels:"); if (labels != null && labels.Count > 0) { foreach (var labelItem in labels) { if (labelItem.Name == "Work") { Console.WriteLine("{0}", labelItem.Name); } } } else { Console.WriteLine("No labels found."); } //Console.Read(); ///--- retrive first email body Message messageFeed = service.Users.Messages.List("me").Execute().Messages.First();//get first latest message UsersResource.MessagesResource.GetRequest getReq = new UsersResource.MessagesResource.GetRequest(service, "me", messageFeed.Id); getReq.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Full; Message message = getReq.Execute(); var BodyOftheFirstMessage = GetMimeString(message.Payload); // Console.WriteLine(BodyOftheFirstMessage); //--------headers of first email foreach (var i in message.Payload.Headers) { if (i.Name == "From") { var x = i.Value; Console.WriteLine("From : " + i.Value); } if (i.Name == "To") { var x = i.Value; Console.WriteLine("To : " + i.Value); } else if (i.Name == "Subject") { var x = i.Value; Console.WriteLine("Subject : " + i.Value); } } }