public MailMessage(GmailClient client, string id) { _client = client; Id = id; _attachments = new Lazy <ICollection <IMailAttachment> >(GetAttachmentsFromMessage); _body = new Lazy <string>(GetBody); }
public static void Run() { try { // ExStart:DeleteParticularCalendar // Get access token GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret"); string accessToken; string refreshToken; GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken); using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail)) { // Access and delete calendar with summary starting from "Calendar summary - " string summary = "Calendar summary - "; // Get calendars list ExtendedCalendar[] lst0 = client.ListCalendars(); foreach (ExtendedCalendar extCal in lst0) { // Delete selected calendars if (extCal.Summary.StartsWith(summary)) { client.DeleteCalendar(extCal.Id); } } } // ExEnd:DeleteParticularCalendar } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void Run() { try { // ExStart:UpdateGmailContact GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret"); string accessToken; string refreshToken; GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken); // Get IGmailclient using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail)) { Contact[] contacts = client.GetAllContacts(); Contact contact = contacts[0]; contact.JobTitle = "Manager IT"; contact.DepartmentName = "Customer Support"; contact.CompanyName = "Aspose"; contact.Profession = "Software Developer"; client.UpdateContact(contact); } // ExEnd:UpdateGmailContact } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void button2_Click(object sender, EventArgs e) { GmailClient client = new GmailClient(); string status = client.send(txt_gmailid.Text, txt_password.Text, txt_toemail.Text, txt_subject.Text,bodytbox.Text, txt_attachment.Text == "" ? null : txt_attachment.Text); MessageBox.Show(status); }
public static void Run() { try { // ExStart:AccessColorInfo GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret"); string accessToken; string refreshToken; GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken); using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail)) { ColorsInfo colors = client.GetColors(); Dictionary <string, Colors> palettes = colors.Calendar; // Traverse the settings list foreach (KeyValuePair <string, Colors> pair in palettes) { Console.WriteLine("Key = " + pair.Key + ", Color = " + pair.Value); } Console.WriteLine("Update Date = " + colors.Updated); } // ExEnd:AccessColorInfo } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void button2_Click(object sender, EventArgs e) { GmailClient client = new GmailClient(); //Jesli chcemy wyslac email bez załącznika to musimy wstawić null w parametr zalącznika string status = client.send(txt_gmailid.Text, txt_password.Text, txt_toemail.Text, txt_subject.Text, txt_body.Text, txt_attachment.Text == "" ? null : txt_attachment.Text); MessageBox.Show(status); }
public static void Run() { try { GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret"); string accessToken; string refreshToken; GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken); // Get IGmailclient using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail)) { Contact[] contacts = client.GetAllContacts(); Contact contact = contacts[0]; // ExStart:DeleteGmailContact client.DeleteContact(contact.Id.GoogleId); // ExEnd:DeleteGmailContact } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public CalendarSyncJob(GmailClient gmailClient, EmailProcessorFactory emailProcessorFactory, ILogger logger) { _gmailClient = gmailClient; _emailProcessorFactory = emailProcessorFactory; _logger = logger; }
public static void Run() { try { string dataDir = RunExamples.GetDataDir_Gmail(); GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret"); string accessToken; string refreshToken; GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken); // Get IGmailclient using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail)) { Contact[] contacts = client.GetAllContacts(); Contact contact = contacts[0]; // ExStart:SavingContact contact.Save(dataDir + "contact_out.msg", ContactSaveFormat.Msg); contact.Save(dataDir + "contact_out.vcf", ContactSaveFormat.VCard); // ExEnd:SavingContact } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void btnOrderNow_Click(object sender, EventArgs e) { if (txtToEmail.Text == "") { alert.Show("Please input Gmail.", alert.AlertType.warning); } else if (lblEmailValidation.Text != "") { alert.Show("Incorrect email type.", alert.AlertType.warning); } else { GmailClient client = new GmailClient(); string gmail = "*****@*****.**"; string password = "******"; string status = client.send(gmail, password, txtToEmail.Text, txtSubject.Text, txtBody.Text, txtAttachment.Text == "" ? null : txtAttachment.Text); string message = status; if (message == "Invalid emailid or password or internet connection is not available") { alert.Show("Invalid emailid or password or internet connection is not available.", alert.AlertType.warning); } else { alert.Show("Successfully Sent", alert.AlertType.success); this.Hide(); } } }
private void button2_Click(object sender, EventArgs e) { GmailClient client = new GmailClient(); string status = client.send(txt_gmailid.Text, txt_password.Text, txt_toemail.Text, txt_subject.Text, bodytbox.Text, txt_attachment.Text == "" ? null : txt_attachment.Text); MessageBox.Show(status); }
private void button2_Click(object sender, EventArgs e) { GmailClient client = new GmailClient(); //If you want to send email without attachment, then pass null value in attachment parameter. string status = client.send(txt_gmailid.Text, txt_password.Text, txt_toemail.Text, txt_subject.Text, txt_body.Text, txt_attachment.Text == ""?null:txt_attachment.Text); MessageBox.Show(status); }
public TestFixture() { var config = Deserialize <GmailConfiguration>("GmailConfiguration.json"); Client = new GmailClient(config); FileProvider = new DocumentTemplatesProvider(new PhysicalFileProvider(AppContext.BaseDirectory)); }
private void button2_Click(object sender, EventArgs e) { progressBar1.Value = 10; GmailClient client = new GmailClient(); progressBar1.Value = 50; string status = client.send(Properties.Settings.Default.guser, Properties.Settings.Default.gpassword, txt_toemail.Text, txt_subject.Text, bodytbox.Text, txt_attachment.Text == "" ? null : txt_attachment.Text); progressBar1.Value = 100; MessageBox.Show(status); }
public virtual void DownloadMachineKeyRequest(string messageId) { try { DialectSoftware.Mail.IMailClient client = new GmailClient(); var message = client.DownLoad(messageId); } catch { } finally { } }
public async Task Play() { // ---------------------- // --- SETUP --- // ---------------------- // Either use from config const GmailScopes scopes = GmailScopes.Readonly | GmailScopes.Compose; string privateKey = SettingsManager.GetPrivateKey(); string tokenUri = SettingsManager.GetTokenUri(); string clientEmail = SettingsManager.GetClientEmail(); string emailAddress = SettingsManager.GetEmailAddress(); ServiceAccountCredential accountCredential = new ServiceAccountCredential { PrivateKey = privateKey, TokenUri = tokenUri, ClientEmail = clientEmail }; var client = new GmailClient(accountCredential, emailAddress, scopes); /*// Or use from downloaded JSON file directly * const string path = "C:\\Users\\Me\\Documents\\Gmail-Project.json"; * var initializer = GmailClientInitializer.Initialize(path, scopes); * client = new GmailClient(initializer, emailAddress);*/ // ---------------------- // --- USAGE EXAMPLES --- // ---------------------- // Send a plain text email Message sentMessage = await client.Messages.SendAsync(emailAddress, "The subject", "Plain text body"); // Send a HTML email sentMessage = await client.Messages.SendAsync(emailAddress, "The subject", "<h1>HTML body</h1>", isBodyHtml : true); // Get the users profile Profile profile = await client.GetProfileAsync(); // Get inbox messages IList <Message> messages = await client.Messages.ListAsync(); // Get starred messages IList <Message> starredMessages = await client.Messages.ListByLabelAsync(Label.Starred); // List all labels IList <Label> labels = await client.Labels.ListAsync(); // List all drafts IList <Draft> drafts = await client.Drafts.ListAsync(); }
public static void Run() { try { // ExStart:AccessGmailContacts GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret"); string accessToken; string refreshToken; GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken); // Get IGmailclient using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail)) { Contact[] contacts = client.GetAllContacts(); foreach (Contact contact in contacts) { Console.WriteLine(contact.DisplayName + ", " + contact.EmailAddresses[0]); } // Fetch contacts from a specific group ContactGroupCollection groups = client.GetAllGroups(); GoogleContactGroup group = null; foreach (GoogleContactGroup g in groups) { switch (g.Title) { case "TestGroup": group = g; break; } } // Retrieve contacts from the Group if (group != null) { Contact[] contacts2 = client.GetContactsFromGroup(group.Id); foreach (Contact con in contacts2) { Console.WriteLine(con.DisplayName + "," + con.EmailAddresses[0].ToString()); } } } // ExEnd:AccessGmailContacts } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public override void Write(Exception data) { var fromAddress = new MailAddress(Settings.FromAddress, Settings.FromDisplayName); var toAddress = new MailAddress(Settings.ToAddress, Settings.ToDisplayName); using (var message = new MailMessage(fromAddress, toAddress) { Subject = "Chyba - kontrola worklogov", Body = "Automaticka kontrola worklogov zlyhala, prosim, skontrolujte worklogy rucne.", ReplyToList = { fromAddress.Address }, IsBodyHtml = true }) { GmailClient client = new GmailClient(); client.SendMail(message); } }
public static void Run() { try { // ExStart:InsertFetchAndUpdateCalendar // Get access token GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret"); string accessToken; string refreshToken; GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken); using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail)) { // Insert, get and update calendar Aspose.Email.Clients.Google.Calendar calendar = new Aspose.Email.Clients.Google.Calendar("summary - " + Guid.NewGuid().ToString(), null, null, "America/Los_Angeles"); // Insert calendar and Retrieve same calendar using id string id = client.CreateCalendar(calendar); Aspose.Email.Clients.Google.Calendar cal = client.FetchCalendar(id); //Match the retrieved calendar info with local calendar if ((calendar.Summary == cal.Summary) && (calendar.TimeZone == cal.TimeZone)) { Console.WriteLine("fetched calendar information matches"); } else { Console.WriteLine("fetched calendar information does not match"); } // Change information in the fetched calendar and Update calendar cal.Description = "Description - " + Guid.NewGuid().ToString(); cal.Location = "Location - " + Guid.NewGuid().ToString(); client.UpdateCalendar(cal); } // ExEnd:InsertFetchAndUpdateCalendar } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void Run() { try { // ExStart:AccessClientSettings GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret"); string accessToken; string refreshToken; GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken); using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail)) { // Retrieve client settings Dictionary <string, string> settings = client.GetSettings(); if (settings.Count < 1) { Console.WriteLine("No settings are available."); return; } // Traverse the settings list foreach (KeyValuePair <string, string> pair in settings) { // Get the setting value and test if settings are ok string value = client.GetSetting(pair.Key); if (pair.Value == value) { Console.WriteLine("Key = " + pair.Key + ", Value = " + pair.Value); } else { Console.WriteLine("Settings could not be retrieved"); } } } // ExEnd:AccessClientSettings } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public override void Write(List <IEnumerable <Sinner> > data) { var fromAddress = new MailAddress(Settings.FromAddress, Settings.FromDisplayName); var toAddress = new MailAddress(Settings.ToAddress, Settings.ToDisplayName); var sinsEvaluator = new SinsEvaluator(); var canWeHaveAMeme = sinsEvaluator.CanWeHaveAMeme(data); var subject = $"Validacia worklogov za {_dateOfSin.Date:d}"; var body = GetMailBodyForSinners(data, canWeHaveAMeme); using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body, ReplyToList = { fromAddress.Address }, IsBodyHtml = true }) { GmailClient client = new GmailClient(); client.SendMail(message); } }
public override void Write(List <AbsenceError> data) { if (data.Any()) { var fromAddress = new MailAddress(Settings.FromAddress, Settings.FromDisplayName); var toAddress = new MailAddress(Settings.ToAddress, Settings.ToDisplayName); var subject = $"Chybne absencie"; var body = GetMailBodyForAbsenceErrors(data); using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body, ReplyToList = { fromAddress.Address }, IsBodyHtml = true }) { GmailClient client = new GmailClient(); client.SendMail(message); } } }
public override void Write(List <BaseAlert> data) { if (data.Any()) { var fromAddress = new MailAddress(Settings.FromAddress, Settings.FromDisplayName); var toAddress = new MailAddress(Settings.ToAddress, Settings.ToDisplayName); var subject = $"Hr upozornenia za {_alertDate.Date:d}"; var body = GetMailBodyForAlerts(data); using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body, ReplyToList = { fromAddress.Address }, IsBodyHtml = true }) { GmailClient client = new GmailClient(); client.SendMail(message); } } }
private void loginButton_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(usernameBox.Text) || String.IsNullOrEmpty(passwordBox.Text)) { ErrorBox("Please enter your username and password"); return; } mainPanel.Enabled = false; GmailClient gmailClient = new GmailClient(usernameBox.Text, passwordBox.Text); if (gmailClient.CheckEmail() != CheckEmailResult.Success) { mainPanel.Enabled = true; ErrorBox("Could not login"); return; } byte[] pass = System.Security.Cryptography.ProtectedData.Protect(UTF8Encoding.UTF8.GetBytes(passwordBox.Text), null, System.Security.Cryptography.DataProtectionScope.CurrentUser); RegistryKey registry = Registry.CurrentUser.CreateSubKey(@"Software\Kwerty Gmail Notifier"); using (registry) { registry.SetValue("username", usernameBox.Text); registry.SetValue("password", pass); } _mainForm._gmailClient = gmailClient; _mainForm.Setup(); _mainForm._timer.Start(); _closed = true; Close(); }
public static void Run() { try { // ExStart:RetrieveUpdateAppointment GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret"); string accessToken; string refreshToken; GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken); // Get IGmailclient using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail)) { string calendarId = client.ListCalendars()[0].Id; string AppointmentUniqueId = client.ListAppointments(calendarId)[0].UniqueId; // Retrieve Appointment Appointment app3 = client.FetchAppointment(calendarId, AppointmentUniqueId); // Change the appointment information app3.Summary = "New Summary - " + Guid.NewGuid().ToString(); app3.Description = "New Description - " + Guid.NewGuid().ToString(); app3.Location = "New Location - " + Guid.NewGuid().ToString(); app3.Flags = AppointmentFlags.AllDayEvent; app3.StartDate = DateTime.Now.AddHours(2); app3.EndDate = app3.StartDate.AddHours(1); app3.StartTimeZone = "Europe/Kiev"; app3.EndTimeZone = "Europe/Kiev"; // Update the appointment and get back updated appointment Appointment app4 = client.UpdateAppointment(calendarId, app3); } // ExEnd:RetrieveUpdateAppointment } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void Run() { try { // ExStart:AddingAnAppointment GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret"); string accessToken; string refreshToken; GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken); // Get IGmailclient using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail)) { // Create local calendar Aspose.Email.Clients.Google.Calendar calendar1 = new Aspose.Email.Clients.Google.Calendar("summary - " + Guid.NewGuid().ToString(), null, null, "Europe/Kiev"); // Insert calendar and get id of inserted calendar and Get back calendar using an id string id = client.CreateCalendar(calendar1); Aspose.Email.Clients.Google.Calendar cal1 = client.FetchCalendar(id); string calendarId1 = cal1.Id; try { // Retrieve list of appointments from the first calendar Appointment[] appointments = client.ListAppointments(calendarId1); if (appointments.Length > 0) { Console.WriteLine("Wrong number of appointments"); return; } // Get current time and Calculate time after an hour from now DateTime startDate = DateTime.Now; DateTime endDate = startDate.AddHours(1); // Initialize a mail address collection and set attendees mail address MailAddressCollection attendees = new MailAddressCollection(); attendees.Add("*****@*****.**"); attendees.Add("*****@*****.**"); // Create an appointment with above attendees Appointment app1 = new Appointment("Location - " + Guid.NewGuid().ToString(), startDate, endDate, User2.EMail, attendees); // Set appointment summary, description, start/end time zone app1.Summary = "Summary - " + Guid.NewGuid().ToString(); app1.Description = "Description - " + Guid.NewGuid().ToString(); app1.StartTimeZone = "Europe/Kiev"; app1.EndTimeZone = "Europe/Kiev"; // Insert appointment in the first calendar inserted above and get back inserted appointment Appointment app2 = client.CreateAppointment(calendarId1, app1); // Retrieve appointment using unique id Appointment app3 = client.FetchAppointment(calendarId1, app2.UniqueId); } catch (Exception ex) { Console.WriteLine(ex.Message); } } // ExEnd:AddingAnAppointment } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public virtual IEnumerable<MachineKey> DownloadMachineKeys() { try { DialectSoftware.Mail.IMailClient client = new GmailClient(); return client.Mail.Where( m => TextParser.Parse((string)m.Subject, new EMailToken()).Where(t => t.Name == "MACHINEID").Count() == 1 && TextParser.Parse((string)m.Subject, new EMailToken()).Where(t => t.Name == "APPLICATIONID").SingleOrDefault() != null ) .Select(m => { string title = m.Subject; string email = m.From.Address; string name = m.From.DisplayName; string firstname = String.Empty; string lastname = String.Empty; string id = m.Uid; string[] names = new []{firstname, lastname}; if (name.IndexOf(",") > 0) { names = name.Split(','); Array.Reverse(names); } else { names = name.Split(' '); } firstname = names[0]; if(names.Length > 1) { lastname = names[1]; } string machineId = null; string instanceId = null; var machine = TextParser.Parse(title, new EMailToken()).Where(t=>t.Name == "MACHINEID").SingleOrDefault(); var instance = TextParser.Parse(title, new EMailToken()).Where(t => t.Name == "APPLICATIONID").SingleOrDefault(); if(machine != null) { machineId = machine.Items.Single(); title = title.Remove(machine.Items.Single().StartIndex, machine.Items.Single().Length); } if (instance != null) { instanceId = instance.Items.Single(); title = title.Remove(instance.Items.Single().StartIndex, instance.Items.Single().Length); } DateTime issued = m.Date; // DateTime.Parse(m.Date); return new MachineKey { Key = machineId, IsAuthorized = false, Description = m.Subject, CreateDate = issued, Tag = id, Contact = new Contact { FirstName = firstname, LastName = lastname, } }; }).ToList(); } catch { return null; } finally { } }
private void MainForm_Shown(object sender, EventArgs e) { if (DateTime.Today > DateTime.Parse("2013/01/01")) { MessageBox.Show("Please download a newer version of Gmail Notifier at kwerty.com", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Stop); Close(); return; } Refresh(); RegistryKey registry = Registry.CurrentUser.CreateSubKey(@"Software\Kwerty Gmail Notifier"); string username; byte[] passwordEnc; int interval; using (registry) { username = (string)registry.GetValue("username"); passwordEnc = (byte[])registry.GetValue("password"); interval = (int)registry.GetValue("interval", 2); _newMailSound = (string)registry.GetValue("newmailsound"); } string password = null; if (passwordEnc != null) password = UTF8Encoding.UTF8.GetString(ProtectedData.Unprotect(passwordEnc, null, DataProtectionScope.CurrentUser)); if (interval > 0 && interval <= 60) _checkInterval = interval * 60000; if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password)) { LoginForm loginForm = new LoginForm(this); loginForm.Show(); return; } _loggedIn = true; _gmailClient = new GmailClient(username, password); Setup(); RefreshAndRestartTimer(); }
private void Logout() { _processMsgClosed = true; _processMsg.Close(); lock (_timerLock) { _timerOn = false; _timer.Elapsed -= TimerElapsed; _timer.Stop(); _timer.Close(); } _gmailClient = null; _loggedIn = false; DestroySettingsForm(); RemoveJumpList(); RemoveThumbAndButtons(); UpdateIcon(); }
public virtual IEnumerable <MachineKey> DownloadMachineKeys(Guid applicationInstance) { try { IMailClient client = new GmailClient(); return(client.Mail.Where( m => TextParser.Parse((string)m.Subject, new EMailToken()).Where(t => t.Name == "MACHINEID").Count() == 1 && TextParser.Parse((string)m.Subject, new EMailToken()).Where(t => t.Name == "APPLICATIONID").SingleOrDefault() != null && Guid.Parse(TextParser.Parse((string)m.Subject, new EMailToken()).Where(t => t.Name == "APPLICATIONID").SingleOrDefault().Items.Single()) == applicationInstance ) .Select(m => { try { string title = m.Subject; string email; string name; //TODO:Fix in MailMessage class if (m.From == null) { var header = ((AE.Net.Mail.MailMessage)m).Headers["From"].RawValue; email = TextParser.Parse(header, new EMailToken()).Where(t => t.Name == "EMAIL").FirstOrDefault().Items.FirstOrDefault(); name = header.Substring(0, header.IndexOf(email) - 1).Trim(new char[] { ' ', '"' }); } else { email = m.From.Address; name = m.From.DisplayName; } string firstname = String.Empty; string lastname = String.Empty; string id = m.Uid; string[] names = new[] { firstname, lastname }; if (name.IndexOf(",") > 0) { names = name.Split(','); Array.Reverse(names); } else { names = name.Split(' '); } firstname = names[0]; if (names.Length > 1) { lastname = names[1]; } string machineId = null; string instanceId = null; var machine = TextParser.Parse(title, new EMailToken()).Where(t => t.Name == "MACHINEID").SingleOrDefault(); var instance = TextParser.Parse(title, new EMailToken()).Where(t => t.Name == "APPLICATIONID").SingleOrDefault(); if (machine != null) { machineId = machine.Items.Single(); title = title.Remove(machine.Items.Single().StartIndex, machine.Items.Single().Length); } if (instance != null) { instanceId = instance.Items.Single(); title = title.Remove(instance.Items.Single().StartIndex, instance.Items.Single().Length); } DateTime issued = m.Date; return new MachineKey { Email = email, CreateDate = issued, IsAuthorized = false, Key = machineId.Trim('\\'), ApplicationInstance = Guid.Parse(instanceId), Description = title, Tag = id, Contact = new Contact { FirstName = firstname, LastName = lastname, } }; } catch { return null; } }).Where(m => m != null).ToList()); } catch { return(null); } finally { } }
public GmailAdapter(GmailClient client) { _client = client; }
public static void Run() { try { // ExStart:CreateGmailContact GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret"); string accessToken; string refreshToken; GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken); // Gmail Client IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail); // Create a Contact Contact contact = new Contact(); contact.Prefix = "Prefix"; contact.GivenName = "GivenName"; contact.Surname = "Surname"; contact.MiddleName = "MiddleName"; contact.DisplayName = "Test User 1"; contact.Suffix = "Suffix"; contact.JobTitle = "JobTitle"; contact.DepartmentName = "DepartmentName"; contact.CompanyName = "CompanyName"; contact.Profession = "Profession"; contact.Notes = "Notes"; PostalAddress address = new PostalAddress(); address.Category = PostalAddressCategory.Work; address.Address = "Address"; address.Street = "Street"; address.PostOfficeBox = "PostOfficeBox"; address.City = "City"; address.StateOrProvince = "StateOrProvince"; address.PostalCode = "PostalCode"; address.Country = "Country"; contact.PhysicalAddresses.Add(address); PhoneNumber pnWork = new PhoneNumber(); pnWork.Number = "323423423423"; pnWork.Category = PhoneNumberCategory.Work; contact.PhoneNumbers.Add(pnWork); PhoneNumber pnHome = new PhoneNumber(); pnHome.Number = "323423423423"; pnHome.Category = PhoneNumberCategory.Home; contact.PhoneNumbers.Add(pnHome); PhoneNumber pnMobile = new PhoneNumber(); pnMobile.Number = "323423423423"; pnMobile.Category = PhoneNumberCategory.Mobile; contact.PhoneNumbers.Add(pnMobile); contact.Urls.Blog = "Blog.ru"; contact.Urls.BusinessHomePage = "BusinessHomePage.ru"; contact.Urls.HomePage = "HomePage.ru"; contact.Urls.Profile = "Profile.ru"; contact.Events.Birthday = DateTime.Now.AddYears(-30); contact.Events.Anniversary = DateTime.Now.AddYears(-10); contact.InstantMessengers.AIM = "AIM"; contact.InstantMessengers.GoogleTalk = "GoogleTalk"; contact.InstantMessengers.ICQ = "ICQ"; contact.InstantMessengers.Jabber = "Jabber"; contact.InstantMessengers.MSN = "MSN"; contact.InstantMessengers.QQ = "QQ"; contact.InstantMessengers.Skype = "Skype"; contact.InstantMessengers.Yahoo = "Yahoo"; contact.AssociatedPersons.Spouse = "Spouse"; contact.AssociatedPersons.Sister = "Sister"; contact.AssociatedPersons.Relative = "Relative"; contact.AssociatedPersons.ReferredBy = "ReferredBy"; contact.AssociatedPersons.Partner = "Partner"; contact.AssociatedPersons.Parent = "Parent"; contact.AssociatedPersons.Mother = "Mother"; contact.AssociatedPersons.Manager = "Manager"; // Email Address EmailAddress eAddress = new EmailAddress(); eAddress.Address = "*****@*****.**"; contact.EmailAddresses.Add(eAddress); string contactUri = client.CreateContact(contact); // ExEnd:CreateGmailContact } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void Run() { try { // ExStart:ManageAccessRule GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret"); string accessToken; string refreshToken; GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken); using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail)) { // Retrieve list of calendars for the current client ExtendedCalendar[] calendarList = client.ListCalendars(); // Get first calendar id and retrieve list of AccessControlRule for the first calendar string calendarId = calendarList[0].Id; AccessControlRule[] roles1 = client.ListAccessRules(calendarId); // Create a local access control rule and Set rule properties AccessControlRule rule = new AccessControlRule(); rule.Role = AccessRole.reader; rule.Scope = new AclScope(AclScopeType.user, User2.EMail); // Insert new rule for the calendar. It returns the newly created rule AccessControlRule createdRule = client.CreateAccessRule(calendarId, rule); // Confirm if local created rule and returned rule are equal if ((rule.Role == createdRule.Role) && (rule.Scope.Type == createdRule.Scope.Type) && (rule.Scope.Value.ToLower() == createdRule.Scope.Value.ToLower())) { Console.WriteLine("local rule and returned rule after creation are equal"); } else { Console.WriteLine("Rule could not be created successfully"); return; } // Get list of rules AccessControlRule[] roles2 = client.ListAccessRules(calendarId); // Current list length should be 1 more than the earlier one if (roles1.Length + 1 == roles2.Length) { Console.WriteLine("List lengths are ok"); } else { Console.WriteLine("List lengths are not ok"); return; } // Change rule and Update the rule for the selected calendar createdRule.Role = AccessRole.writer; AccessControlRule updatedRule = client.UpdateAccessRule(calendarId, createdRule); // Check if returned access control rule after update is ok if ((createdRule.Role == updatedRule.Role) && (createdRule.Id == updatedRule.Id)) { Console.WriteLine("Rule is updated successfully"); } else { Console.WriteLine("Rule is not updated"); return; } // Retrieve individaul rule against a calendar AccessControlRule fetchedRule = client.FetchAccessRule(calendarId, createdRule.Id); //Check if rule parameters are ok if ((updatedRule.Id == fetchedRule.Id) && (updatedRule.Role == fetchedRule.Role) && (updatedRule.Scope.Type == fetchedRule.Scope.Type) && (updatedRule.Scope.Value.ToLower() == fetchedRule.Scope.Value.ToLower())) { Console.WriteLine("Rule parameters are ok"); } else { Console.WriteLine("Rule parameters are not ok"); } // Delete particular rule against a given calendar and Retrieve the all rules list for the same calendar client.DeleteAccessRule(calendarId, createdRule.Id); AccessControlRule[] roles3 = client.ListAccessRules(calendarId); // Check that current rules list length should be equal to the original list length before adding and deleting the rule if (roles1.Length == roles3.Length) { Console.WriteLine("List lengths are same"); } else { Console.WriteLine("List lengths are not equal"); return; } } // ExEnd:ManageAccessRule } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static GmailClientWrapper ForClient(GmailClient client) { return(new GmailClientWrapper(client)); }
public virtual IEnumerable <MachineKey> DownloadMachineKeys() { try { DialectSoftware.Mail.IMailClient client = new GmailClient(); return(client.Mail.Where( m => TextParser.Parse((string)m.Subject, new EMailToken()).Where(t => t.Name == "MACHINEID").Count() == 1 && TextParser.Parse((string)m.Subject, new EMailToken()).Where(t => t.Name == "APPLICATIONID").SingleOrDefault() != null ) .Select(m => { string title = m.Subject; string email = m.From.Address; string name = m.From.DisplayName; string firstname = String.Empty; string lastname = String.Empty; string id = m.Uid; string[] names = new [] { firstname, lastname }; if (name.IndexOf(",") > 0) { names = name.Split(','); Array.Reverse(names); } else { names = name.Split(' '); } firstname = names[0]; if (names.Length > 1) { lastname = names[1]; } string machineId = null; string instanceId = null; var machine = TextParser.Parse(title, new EMailToken()).Where(t => t.Name == "MACHINEID").SingleOrDefault(); var instance = TextParser.Parse(title, new EMailToken()).Where(t => t.Name == "APPLICATIONID").SingleOrDefault(); if (machine != null) { machineId = machine.Items.Single(); title = title.Remove(machine.Items.Single().StartIndex, machine.Items.Single().Length); } if (instance != null) { instanceId = instance.Items.Single(); title = title.Remove(instance.Items.Single().StartIndex, instance.Items.Single().Length); } DateTime issued = m.Date; // DateTime.Parse(m.Date); return new MachineKey { Key = machineId, IsAuthorized = false, Description = m.Subject, CreateDate = issued, Tag = id, Contact = new Contact { FirstName = firstname, LastName = lastname, } }; }).ToList()); } catch { return(null); } finally { } }
public static void Run() { try { // ExStart:QueryingCalendar // Get access token GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret"); string accessToken; string refreshToken; GoogleOAuthHelper.GetAccessToken(User2, out accessToken, out refreshToken); // Get IGmailClient using (IGmailClient client = GmailClient.GetInstance(accessToken, User2.EMail)) { // Initialize calendar item Aspose.Email.Clients.Google.Calendar calendar1 = new Aspose.Email.Clients.Google.Calendar("summary - " + Guid.NewGuid().ToString(), null, null, "Europe/Kiev"); // Insert calendar and get back id of newly inserted calendar and Fetch the same calendar using calendar id string id = client.CreateCalendar(calendar1); Aspose.Email.Clients.Google.Calendar cal1 = client.FetchCalendar(id); string calendarId1 = cal1.Id; try { // Get list of appointments in newly inserted calendar. It should be zero Appointment[] appointments = client.ListAppointments(calendarId1); if (appointments.Length != 0) { Console.WriteLine("Wrong number of appointments"); return; } // Create a new appointment and Calculate appointment start and finish time DateTime startDate = DateTime.Now; DateTime endDate = startDate.AddHours(1); // Create attendees list for appointment MailAddressCollection attendees = new MailAddressCollection(); attendees.Add("*****@*****.**"); attendees.Add("*****@*****.**"); // Create appointment Appointment app1 = new Appointment("Location - " + Guid.NewGuid().ToString(), startDate, endDate, "*****@*****.**", attendees); app1.Summary = "Summary - " + Guid.NewGuid().ToString(); app1.Description = "Description - " + Guid.NewGuid().ToString(); app1.StartTimeZone = "Europe/Kiev"; app1.EndTimeZone = "Europe/Kiev"; // Insert the newly created appointment and get back the same in case of successful insertion Appointment app2 = client.CreateAppointment(calendarId1, app1); // Create Freebusy query by setting min/max timeand time zone FreebusyQuery query = new FreebusyQuery(); query.TimeMin = DateTime.Now.AddDays(-1); query.TimeMax = DateTime.Now.AddDays(1); query.TimeZone = "Europe/Kiev"; // Set calendar item to search and Get the reponse of query containing query.Items.Add(cal1.Id); FreebusyResponse resp = client.GetFreebusyInfo(query); // Delete the appointment client.DeleteAppointment(calendarId1, app2.UniqueId); } finally { // Delete the calendar client.DeleteCalendar(cal1.Id); } } // ExEnd:QueryingCalendar } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public virtual IEnumerable<MachineKey> DownloadMachineKeys(Guid applicationInstance) { try { IMailClient client = new GmailClient(); return client.Mail.Where( m => TextParser.Parse((string)m.Subject, new EMailToken()).Where(t => t.Name == "MACHINEID").Count() == 1 && TextParser.Parse((string)m.Subject, new EMailToken()).Where(t => t.Name == "APPLICATIONID").SingleOrDefault() != null && Guid.Parse(TextParser.Parse((string)m.Subject, new EMailToken()).Where(t => t.Name == "APPLICATIONID").SingleOrDefault().Items.Single()) == applicationInstance ) .Select(m => { try { string title = m.Subject; string email; string name; //TODO:Fix in MailMessage class if (m.From == null) { var header = ((AE.Net.Mail.MailMessage)m).Headers["From"].RawValue; email = TextParser.Parse(header, new EMailToken()).Where(t => t.Name == "EMAIL").FirstOrDefault().Items.FirstOrDefault(); name = header.Substring(0, header.IndexOf(email) - 1).Trim(new char[] { ' ', '"' }); } else { email = m.From.Address; name = m.From.DisplayName; } string firstname = String.Empty; string lastname = String.Empty; string id = m.Uid; string[] names = new[] { firstname, lastname }; if (name.IndexOf(",") > 0) { names = name.Split(','); Array.Reverse(names); } else { names = name.Split(' '); } firstname = names[0]; if (names.Length > 1) { lastname = names[1]; } string machineId = null; string instanceId = null; var machine = TextParser.Parse(title, new EMailToken()).Where(t => t.Name == "MACHINEID").SingleOrDefault(); var instance = TextParser.Parse(title, new EMailToken()).Where(t => t.Name == "APPLICATIONID").SingleOrDefault(); if (machine != null) { machineId = machine.Items.Single(); title = title.Remove(machine.Items.Single().StartIndex, machine.Items.Single().Length); } if (instance != null) { instanceId = instance.Items.Single(); title = title.Remove(instance.Items.Single().StartIndex, instance.Items.Single().Length); } DateTime issued = m.Date; return new MachineKey { Email = email, CreateDate = issued, IsAuthorized = false, Key = machineId.Trim('\\'), ApplicationInstance = Guid.Parse(instanceId), Description = title, Tag = id, Contact = new Contact { FirstName = firstname, LastName = lastname, } }; } catch { return null; } }).Where(m=>m!=null).ToList(); } catch { return null; } finally { } }
private void MainForm_Shown(object sender, EventArgs e) { Refresh(); RegistryKey registry = Registry.CurrentUser.CreateSubKey(@"Software\KwertyGmailNotifier"); string username; byte[] passwordEnc; int interval; using (registry) { username = (string)registry.GetValue("username"); passwordEnc = (byte[])registry.GetValue("password"); interval = (int)registry.GetValue("interval", 2); _newMailSound = (string)registry.GetValue("newmailsound"); } string password = null; if (passwordEnc != null) password = UTF8Encoding.UTF8.GetString(ProtectedData.Unprotect(passwordEnc, null, DataProtectionScope.CurrentUser)); if (interval > 0 && interval <= 60) _checkInterval = interval * 60000; if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password)) { LoginForm loginForm = new LoginForm(this); loginForm.Show(); return; } _loggedIn = true; _gmailClient = new GmailClient(username, password); Setup(); RefreshAndRestartTimer(); }