Exchange Server에서 연락처 작업
EWS로 연락처 가져오기
Aspose.Email은 다음을 제공합니다 EWSClient Exchange Web Services를 사용하여 Microsoft Exchange Server에 연결하는 클래스입니다. 다음 코드 스니펫은 Exchange Web Services를 사용하여 모든 연락처를 읽는 방법을 보여줍니다. 다음 코드 스니펫은 EWS로 연락처를 가져오는 방법을 보여줍니다.
// Create instance of IEWSClient class by giving credentials
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
// List all the contacts
Contact[] contacts = client.getContacts(client.getMailboxInfo().getContactsUri());
for (Contact contact : contacts) {
MapiContact mapiContact = Contact.to_MapiContact(contact);
// Display name and email address
System.out.println("Name: " + mapiContact.getNameInfo().getDisplayName() + "+ Email Address: " + mapiContact.getElectronicAddresses().getEmail1());
}
연락처 이름으로 연락처 해결
다음 코드 스니펫은 EWS를 사용하여 연락처를 가져오는 방법을 보여줍니다.
// Create instance of IEWSClient class by giving credentials
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
// List all the contacts
Contact[] contacts = client.resolveContacts("Changed Name", ExchangeListContactsOptions.FetchPhoto);
for (Contact c : contacts) {
MapiContact contact = Contact.to_MapiContact(c);
// Display name and email address
System.out.println("Name: " + contact.getNameInfo().getDisplayName() + "+ Email Address: " + contact.getElectronicAddresses().getEmail1());
}
연락처 노트 형식 결정
NotesFormat은 TextFormat 열거형에 정의된 연락처 노트 텍스트 형식 유형을 지정합니다.
ID로 연락처 가져오기
다음 코드 샘플과 같이 연락처 ID를 사용하여 서버에서 특정 연락처를 검색할 수 있습니다.
Contact fetchedContact = client.getContact(id);
연락처 추가
다음은 EWSClient 클래스 createContact() 이 메서드는 Exchange Server에 연락처 정보를 추가하는 데 사용할 수 있습니다. createContact() 메서드는 Contact 객체를 입력 매개변수로 사용합니다.
Exchange Server에 연락처를 추가하려면:
- 주소와 자격 증명을 사용하여 EWSClient를 초기화합니다.
- 원하는 속성으로 Contact 객체를 초기화합니다.
- CreateContact 메서드를 호출하여 연락처를 Exchange Server에 추가합니다.
Aspose.Email은 다음을 제공합니다 EWSClient Exchange Web Services를 사용하여 Microsoft Exchange Server에 연결하는 클래스입니다. 다음 코드 스니펫은 Exchange Web Services를 사용하여 Exchange Server에 연락처를 추가하는 방법을 보여줍니다.
// Set mailboxURI, Username, password, domain information
String mailboxUri = "https://ex2010/ews/exchange.asmx";
String username = "test.exchange";
String password = "pwd";
String domain = "ex2010.local";
NetworkCredential credentials = new NetworkCredential(username, password, domain);
IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);
// Create New Contact
Contact contact = new Contact();
// Set general info
contact.setGender(Gender.Male);
contact.setDisplayName("Frank Lin");
contact.setCompanyName("ABC Co.");
contact.setJobTitle("Executive Manager");
PhoneNumber tmp0 = new PhoneNumber();
tmp0.setNumber("123456789");
tmp0.setCategory(PhoneNumberCategory.getHome());
// Add Phone numbers
contact.getPhoneNumbers().add(tmp0);
AssociatedPerson tmp1 = new AssociatedPerson();
tmp1.setName("Catherine");
tmp1.setCategory(AssociatedPersonCategory.getSpouse());
// contact's associated persons
contact.getAssociatedPersons().add(tmp1);
AssociatedPerson tmp2 = new AssociatedPerson();
tmp2.setName("Bob");
tmp2.setCategory(AssociatedPersonCategory.getChild());
contact.getAssociatedPersons().add(tmp2);
AssociatedPerson tmp3 = new AssociatedPerson();
tmp3.setName("Merry");
tmp3.setCategory(AssociatedPersonCategory.getSister());
contact.getAssociatedPersons().add(tmp3);
Url tmp4 = new Url();
tmp4.setHref("www.blog.com");
tmp4.setCategory(UrlCategory.getBlog());
// URLs
contact.getUrls().add(tmp4);
Url tmp5 = new Url();
tmp5.setHref("www.homepage.com");
tmp5.setCategory(UrlCategory.getHomePage());
contact.getUrls().add(tmp5);
EmailAddress tmp6 = new EmailAddress();
tmp6.setAddress("Frank.Lin@Abc.com");
tmp6.setDisplayName("Frank Lin");
tmp6.setCategory(EmailAddressCategory.getEmail1());
// Set contact's Email address
contact.getEmailAddresses().add(tmp6);
try {
client.createContact(contact);
} catch (java.lang.RuntimeException ex) {
System.out.println(ex.getMessage());
}
연락처 업데이트
연락처 정보는 Microsoft Outlook을 사용하여 업데이트할 수 있습니다. Aspose.Email은 Exchange Web Service(EWS)를 사용하여 Exchange Server의 연락처 정보를 업데이트할 수도 있습니다. IEWSClient’s updateContact() 이 메서드는 Exchange Server에서 연락처 정보를 업데이트할 수 있습니다.
IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);
// List all the contacts and Loop through all contacts
Contact[] contacts = client.getContacts(client.getMailboxInfo().getContactsUri());
Contact contact = contacts[0];
System.out.println("Name: " + contact.getDisplayName());
contact.setDisplayName("David Ch");
client.updateContact(contact);
연락처 삭제
다음은 EWSClient class는 다음을 제공합니다 deleteItem Exchange Server의 연락처 폴더에 액세스하고 연락처를 삭제합니다. 이 메서드는 연락처 ID를 입력 매개변수로 사용합니다.
Exchange Server에서 연락처를 삭제하려면:
- 주소와 자격 증명을 사용하여 ExchangeWebServiceClient를 초기화합니다.
- ID를 사용하여 연락처를 삭제합니다.
다음 코드 스니펫은 Exchange Web Service를 사용하여 Exchange Server에서 연락처를 삭제하는 방법을 보여줍니다.
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
String strContactToDelete = "John Teddy";
Contact[] contacts = client.getContacts(client.getMailboxInfo().getContactsUri());
for (Contact contact : contacts) {
if (contact.getDisplayName().equals(strContactToDelete))
client.deleteItem(contact.getId().getEWSId(), DeletionOptions.getDeletePermanently());
}
client.dispose();