private static void AddUnExistContactFromWeb() { int ex = 0; MAPIFolder folder = outlook.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderContacts); foreach (Person nc in webContact) { bool isExist = false; foreach (ContactItem oc in oldData) { if (oc.Email1Address.Equals(nc.email)) { isExist = true; break; } } if (!isExist) { Console.WriteLine("[NEW EMPLOYEE] " + nc.belongClass + ",\t" + nc.name + ",\t" + nc.email); ContactItem person = (ContactItem)outlook.CreateItem(OlItemType.olContactItem); person.Email1Address = nc.email; person.FullName = nc.name; person.Department = nc.belongClass; person.Save(); ex++; } } if (ex == 0) { PlayText("[MESSAGE] No more employee"); } }
public static void Update(this ContactItem thisContactItem, ExchangeUser user) { thisContactItem.Email1Address = user.PrimarySmtpAddress; thisContactItem.BusinessTelephoneNumber = user.BusinessTelephoneNumber; thisContactItem.MobileTelephoneNumber = user.MobileTelephoneNumber; thisContactItem.CompanyName = user.CompanyName; thisContactItem.Department = user.Department; thisContactItem.FirstName = user.FirstName; thisContactItem.LastName = user.LastName; thisContactItem.FullName = user.Name; thisContactItem.JobTitle = user.JobTitle; thisContactItem.OfficeLocation = user.OfficeLocation; thisContactItem.Save(); }
public void AddNewContact(Model.Contact contact) { Application outlookApp = new Application(); ContactItem newContact = (ContactItem)outlookApp.CreateItem(OlItemType.olContactItem); newContact.FullName = contact.FullName; newContact.Email1Address = contact.Email; newContact.HomeAddress = contact.Address; newContact.HomeTelephoneNumber = contact.HomePhone; newContact.MobileTelephoneNumber = contact.MobilePhone; newContact.BusinessTelephoneNumber = contact.BusinessPhone; newContact.BusinessFaxNumber = contact.BusinessFax; newContact.Save(); //newContact.Display(true); }
public void CreateOutlookContact(string fName = "", string lName = "", string email = "", string address = "", string phone = "") { Microsoft.Office.Interop.Outlook.Application outlookObj = new Microsoft.Office.Interop.Outlook.Application(); ContactItem contact = (ContactItem)outlookObj.CreateItem(OlItemType.olContactItem); try { contact.FirstName = fName; contact.LastName = lName; contact.Email1Address = email; contact.HomeAddress = address; contact.HomeTelephoneNumber = phone; contact.Save(); } catch { InformationBox.Show("Error saving Outlook contact", "Outlook Error"); } }
public static void Update(this ContactItem thisContactItem, ExchangeDistributionList distributionList) { var user = distributionList.GetExchangeUser(); if (user != null) { thisContactItem.Email1Address = distributionList.PrimarySmtpAddress; thisContactItem.LastName = distributionList.Name; thisContactItem.FirstName = string.Empty; thisContactItem.BusinessTelephoneNumber = user.BusinessTelephoneNumber; thisContactItem.MobileTelephoneNumber = user.MobileTelephoneNumber; thisContactItem.CompanyName = user.CompanyName; thisContactItem.Department = user.Department; thisContactItem.OfficeLocation = user.OfficeLocation; thisContactItem.Save(); } }
/// <summary> /// Returns a syncronization id for a given contact. If there is no syncronization id, a new one will be /// created and saved to outlook. If saving the contact does fail because of authorization, NO exception /// will be thrown. /// </summary> /// <param name="outlookContact"> /// the outlook contact to handle /// </param> /// <param name="contactList"> /// The contact List to lookup duplicates. /// </param> /// <returns> /// the corresponding Guid /// </returns> private static Guid GetStandardContactId(ContactItem outlookContact, IEnumerable <StdContact> contactList) { if (outlookContact == null) { throw new ArgumentNullException("outlookContact"); } var newId = Guid.NewGuid(); try { // try to read the contact id property - generate one if it's not there var contactIdObject = outlookContact.UserProperties[ContactIdOutlookPropertyName] ?? outlookContact.UserProperties.Add( ContactIdOutlookPropertyName, OlUserPropertyType.olText, true, OlFormatText.olFormatTextText); // test if the value is a valid id if (contactIdObject.Value.ToString().Length != 36) { // use the formerly generated id if the one from outlook is not valid contactIdObject.Value = newId.ToString(); outlookContact.Save(); } // finally read the id from the property newId = new Guid(contactIdObject.Value.ToString()); } catch (UnauthorizedAccessException) { // if we are not authorized to write back the id, we will assume a new id } var guid = newId; if (contactList != null && contactList.Where(x => x.Id == guid).Count() > 0) { newId = Guid.NewGuid(); } return(newId); }
private void SaveCustomInformation() { dirty = false; if (ContactViewModel.Responsibility != null) { //SetProperty(responsibilityProperty, ContactViewModel.Responsibility, OlUserPropertyType.olText); //SetProperty(LastCheckedDateProperty, ContactViewModel.LastCheckedDate, OlUserPropertyType.olDateTime); if (!String.IsNullOrEmpty(ContactViewModel.Responsibility.Email)) { item.User1 = ContactViewModel.Responsibility.Email; } if (ContactViewModel.LastCheckedDate.HasValue) { item.Anniversary = ContactViewModel.LastCheckedDate.Value; } item.Save(); } //item.UserProperties[responsibilityProperty].Value = ContactViewModel.Responsibility; //item.UserProperties[LastCheckedDateProperty].Value = ContactViewModel.LastCheckedDate; //OlUserPropertyType.olText //MessageBox.Show(ContactViewModel.Responsibility); }
private static void AddUnExistContactFromPST() { MAPIFolder folder = outlook.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderContacts); foreach (ContactItem nc in newData) { bool isExist = false; foreach (ContactItem oc in oldData) { if (oc.Email1Address.Equals(nc.Email1Address)) { isExist = true; break; } } if (!isExist) { ContactItem tc = nc.Copy(); tc.Move(folder); tc.Save(); } } }
/// <summary> /// Syncs the outlook contact. /// </summary> /// <param name="outlookContact">The outlook contact.</param> /// <param name="googleContacts">The google contacts.</param> private void SyncOutlookContact(ContactItem outlookContact, IEnumerable <Contact> googleContacts) { var mergeables = googleContacts.Mergeable(outlookContact).ToList(); // continue with next, if modificationdate is older then other side. if (ApplicationData.ContactBehavior == ContactBehavior.Automatic && mergeables.Any() && outlookContact.LastModificationTime < mergeables.First().ContactEntry.Edited.DateValue) { return; } // Get or Create Contact and merge informations Contact googleContact; var googleGroups = Repository.GoogleData.GetGroups(); if (mergeables.Any()) { googleContact = mergeables.First(); var changed = googleContact.MergeWith(outlookContact, googleGroups); if (changed) { this.Repository.GoogleData.ContactsRequest.Update(googleContact); } } else { googleContact = new Contact(); googleContact.MergeWith(outlookContact, googleGroups); this.Repository.GoogleData.ContactsRequest.Insert(ApplicationData.GoogleContactsUri, googleContact); } // Set GoogleId and Picture var outlookChanged = outlookContact.UserProperties.SetProperty("GoogleId", googleContact.Id); if (ApplicationData.ContactBehavior != ContactBehavior.GoogleOverOutlook && outlookContact.HasNewPicture()) { try { this.Repository.GoogleData.ContactsRequest.SetPhoto(googleContact, outlookContact.GetPicture(), "image/jpg"); googleContact = this.Repository.GoogleData.ContactsRequest.Retrieve(googleContact); outlookChanged |= outlookContact.UserProperties.SetProperty("GooglePicture", googleContact.PhotoEtag); } catch (IOException ex) { Debug.Write(ex.Message); new EventLogPermission(EventLogPermissionAccess.Administer, ".").PermitOnly(); EventLog.WriteEntry("GoogleSync Addin", ex.ToString(), EventLogEntryType.Warning); } catch (UnauthorizedAccessException ex) { Debug.Write(ex.Message); new EventLogPermission(EventLogPermissionAccess.Administer, ".").PermitOnly(); EventLog.WriteEntry("GoogleSync Addin", ex.ToString(), EventLogEntryType.Warning); } } if (outlookChanged) { outlookContact.Save(); } }
/// <summary> /// Syncs the outlook contact. /// </summary> /// <param name="outlookContact">The outlook contact.</param> /// <param name="googleContacts">The google contacts.</param> private void SyncOutlookContact(ContactItem outlookContact, IEnumerable<Contact> googleContacts) { var mergeables = googleContacts.Mergeable(outlookContact).ToList(); // continue with next, if modificationdate is older then other side. if (ApplicationData.ContactBehavior == ContactBehavior.Automatic && mergeables.Any() && outlookContact.LastModificationTime < mergeables.First().ContactEntry.Edited.DateValue) return; // Get or Create Contact and merge informations Contact googleContact; var googleGroups = Repository.GoogleData.GetGroups(); if (mergeables.Any()) { googleContact = mergeables.First(); var changed = googleContact.MergeWith(outlookContact, googleGroups); if (changed) this.Repository.GoogleData.ContactsRequest.Update(googleContact); } else { googleContact = new Contact(); googleContact.MergeWith(outlookContact, googleGroups); this.Repository.GoogleData.ContactsRequest.Insert(ApplicationData.GoogleContactsUri, googleContact); } // Set GoogleId and Picture var outlookChanged = outlookContact.UserProperties.SetProperty("GoogleId", googleContact.Id); if (ApplicationData.ContactBehavior != ContactBehavior.GoogleOverOutlook && outlookContact.HasNewPicture()) { try { this.Repository.GoogleData.ContactsRequest.SetPhoto(googleContact, outlookContact.GetPicture(), "image/jpg"); googleContact = this.Repository.GoogleData.ContactsRequest.Retrieve(googleContact); outlookChanged |= outlookContact.UserProperties.SetProperty("GooglePicture", googleContact.PhotoEtag); } catch (IOException ex) { Debug.Write(ex.Message); new EventLogPermission(EventLogPermissionAccess.Administer, ".").PermitOnly(); EventLog.WriteEntry("GoogleSync Addin", ex.ToString(), EventLogEntryType.Warning); } catch (UnauthorizedAccessException ex) { Debug.Write(ex.Message); new EventLogPermission(EventLogPermissionAccess.Administer, ".").PermitOnly(); EventLog.WriteEntry("GoogleSync Addin", ex.ToString(), EventLogEntryType.Warning); } } if (outlookChanged) outlookContact.Save(); }
private void UpdateContactDataFromGoogle(Contact gContact, ContactItem oContact) { if (gContact.Organizations.Count > 0) { oContact.CompanyName = gContact.Organizations[0].Name; oContact.JobTitle = gContact.Organizations[0].Title; } //oContact.WebPage = gContact.weex var qryBusinessAddress = gContact.PostalAddresses.Where(p => !p.Home); if (qryBusinessAddress.Count() > 0) { oContact.BusinessAddress = qryBusinessAddress.First().Value; } else oContact.BusinessAddress = ""; var qryHomeAddress = gContact.PostalAddresses.Where(p => p.Home); if (qryHomeAddress.Count() > 0) { oContact.HomeAddress = qryHomeAddress.First().Value; } else oContact.HomeAddress = ""; try { oContact.Email1Address = gContact.Emails[0].Address; oContact.Email1DisplayName = gContact.Title; } catch { oContact.Email1Address = ""; oContact.Email1DisplayName = ""; } try { oContact.Email2Address = gContact.Emails[1].Address; oContact.Email2DisplayName = gContact.Title; } catch { oContact.Email2Address = ""; oContact.Email2DisplayName = ""; } try { oContact.Email3Address = gContact.Emails[2].Address; oContact.Email3DisplayName = gContact.Title; } catch { oContact.Email3Address = ""; oContact.Email3DisplayName = ""; } if (gContact.PrimaryEmail != null) { if (gContact.Title != gContact.PrimaryEmail.Address) { oContact.FullName = gContact.Title; } } else { oContact.FullName = gContact.Title; } var qryBusinessPhone = gContact.Phonenumbers.Where(p => p.Work); if (qryBusinessPhone.Count() > 0) { oContact.BusinessTelephoneNumber = qryBusinessPhone.First().Value; } else oContact.BusinessTelephoneNumber = ""; var qryHomePhone = gContact.Phonenumbers.Where(p => p.Home); if (qryHomePhone.Count() > 0) { oContact.HomeTelephoneNumber = qryHomePhone.First().Value; } else oContact.HomeTelephoneNumber = ""; var qryWorkFax = gContact.Phonenumbers.Where(p => p.Rel == ContactsRelationships.IsWorkFax); if (qryWorkFax.Count() > 0) { oContact.BusinessFaxNumber = qryWorkFax.First().Value; } else oContact.BusinessFaxNumber = ""; var qryHomeFax = gContact.Phonenumbers.Where(p => p.Rel == ContactsRelationships.IsHomeFax); if (qryHomeFax.Count() > 0) { oContact.HomeFaxNumber = qryHomeFax.First().Value; } else oContact.HomeFaxNumber = ""; var qryMobile = gContact.Phonenumbers.Where(p => p.Rel == ContactsRelationships.IsMobile); if (qryMobile.Count() > 0) { oContact.MobileTelephoneNumber = qryMobile.First().Value; } else oContact.MobileTelephoneNumber = ""; oContact.Save(); }
private void UpdateContactDataFromGoogle(Contact gContact, ContactItem oContact) { if (gContact.Organizations.Count > 0) { oContact.CompanyName = gContact.Organizations[0].Name; oContact.JobTitle = gContact.Organizations[0].Title; } //oContact.WebPage = gContact.weex var qryBusinessAddress = gContact.PostalAddresses.Where(p => !p.Home); if (qryBusinessAddress.Count() > 0) { oContact.BusinessAddress = qryBusinessAddress.First().Value; } else { oContact.BusinessAddress = ""; } var qryHomeAddress = gContact.PostalAddresses.Where(p => p.Home); if (qryHomeAddress.Count() > 0) { oContact.HomeAddress = qryHomeAddress.First().Value; } else { oContact.HomeAddress = ""; } try { oContact.Email1Address = gContact.Emails[0].Address; oContact.Email1DisplayName = gContact.Title; } catch { oContact.Email1Address = ""; oContact.Email1DisplayName = ""; } try { oContact.Email2Address = gContact.Emails[1].Address; oContact.Email2DisplayName = gContact.Title; } catch { oContact.Email2Address = ""; oContact.Email2DisplayName = ""; } try { oContact.Email3Address = gContact.Emails[2].Address; oContact.Email3DisplayName = gContact.Title; } catch { oContact.Email3Address = ""; oContact.Email3DisplayName = ""; } if (gContact.PrimaryEmail != null) { if (gContact.Title != gContact.PrimaryEmail.Address) { oContact.FullName = gContact.Title; } } else { oContact.FullName = gContact.Title; } var qryBusinessPhone = gContact.Phonenumbers.Where(p => p.Work); if (qryBusinessPhone.Count() > 0) { oContact.BusinessTelephoneNumber = qryBusinessPhone.First().Value; } else { oContact.BusinessTelephoneNumber = ""; } var qryHomePhone = gContact.Phonenumbers.Where(p => p.Home); if (qryHomePhone.Count() > 0) { oContact.HomeTelephoneNumber = qryHomePhone.First().Value; } else { oContact.HomeTelephoneNumber = ""; } var qryWorkFax = gContact.Phonenumbers.Where(p => p.Rel == ContactsRelationships.IsWorkFax); if (qryWorkFax.Count() > 0) { oContact.BusinessFaxNumber = qryWorkFax.First().Value; } else { oContact.BusinessFaxNumber = ""; } var qryHomeFax = gContact.Phonenumbers.Where(p => p.Rel == ContactsRelationships.IsHomeFax); if (qryHomeFax.Count() > 0) { oContact.HomeFaxNumber = qryHomeFax.First().Value; } else { oContact.HomeFaxNumber = ""; } var qryMobile = gContact.Phonenumbers.Where(p => p.Rel == ContactsRelationships.IsMobile); if (qryMobile.Count() > 0) { oContact.MobileTelephoneNumber = qryMobile.First().Value; } else { oContact.MobileTelephoneNumber = ""; } oContact.Save(); }
public void Save() { contact.Save(); }