עבודה עם רשימות תפוצה ב‑Exchange Server
עבודה עם רשימות הפצה
Aspose.Email API מספקת את היכולת ליצור ולקרוא רשימות הפצה מהשרת Exchange. ניתן ליצור רשימות הפצה בשרת וכן להוסיף אליהן חברים באמצעות IEWSClient. מאמר זה מציג כיצד לעבוד עם רשימות הפצה בשרת Exchange.
יצירת רשימת הפצה
קטע הקוד הבא מציג כיצד ליצור רשימת הפצה.
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
ExchangeDistributionList distributionList = new ExchangeDistributionList();
distributionList.setDisplayName("test private list");
MailAddressCollection members = new MailAddressCollection();
members.add("address1@host.com");
members.add("address2@host.com");
members.add("address3@host.com");
client.createDistributionList(distributionList, members);
אחזור רשימת הפצה פרטית
קטע הקוד הבא מציג כיצד לאחזר רשימת הפצה פרטית.
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
ExchangeDistributionList[] distributionLists = client.listDistributionLists();
for (ExchangeDistributionList distributionList : distributionLists) {
MailAddressCollection members = client.fetchDistributionList(distributionList);
for (MailAddress member : (Iterable<MailAddress>) members) {
System.out.println(member.getAddress());
}
}
הרחבת רשימת הפצה ציבורית
קטע הקוד הבא מציג כיצד להרחיב את רשימת ההפצה הציבורית.
MailAddressCollection members = client.expandDistributionList(new MailAddress("public.distribution.list@host.com"));
for (MailAddress member : (Iterable<MailAddress>) members) {
System.out.println(member.getAddress());
}
הוספת חברים
הוספת חברים לרשימת הפצה פרטית
קטע הקוד הבא מציג כיצד להוסיף חברים לרשימת הפצה פרטית.
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
ExchangeDistributionList[] distributionLists = client.listDistributionLists();
MailAddressCollection newMembers = new MailAddressCollection();
newMembers.add("address4@host.com");
newMembers.add("address5@host.com");
client.addToDistributionList(distributionLists[0], newMembers);
הוספת חברים ללא רישום
קטע הקוד הבא מציג כיצד להוסיף חברים ללא רישום.
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
ExchangeDistributionList distributionList = new ExchangeDistributionList();
distributionList.setId("list's id");
distributionList.setChangeKey("list's change key");
MailAddressCollection newMembers = new MailAddressCollection();
newMembers.add("address6@host.com");
client.addToDistributionList(distributionList, newMembers);
שליחה לרשימת הפצה פרטית
קטע הקוד הבא מציג כיצד לשלוח הודעה לרשימת הפצה פרטית.
ExchangeDistributionList[] distributionLists = client.listDistributionLists();
MailAddress distributionListAddress = distributionLists[0].toMailAddress();
MailMessage message = new MailMessage(new MailAddress("from@host.com"), distributionListAddress);
message.setSubject("sendToPrivateDistributionList");
client.send(message);
מחיקת חברים
מחיקת חברים מרשימת הפצה פרטית
קטע הקוד הבא מציג כיצד למחוק חברים מרשימת הפצה פרטית.
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
ExchangeDistributionList[] distributionLists = client.listDistributionLists();
MailAddressCollection members = client.fetchDistributionList(distributionLists[0]);
MailAddressCollection membersToDelete = new MailAddressCollection();
membersToDelete.addMailAddress(members.get_Item(0));
membersToDelete.addMailAddress(members.get_Item(1));
client.deleteFromDistributionList(distributionLists[0], membersToDelete);
מחיקת חברים ללא רישום
קטע הקוד הבא מציג כיצד למחוק חברים ללא רישום.
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
ExchangeDistributionList distributionList = new ExchangeDistributionList();
distributionList.setId("list's id");
distributionList.setChangeKey("list's change key");
MailAddressCollection membersToDelete = new MailAddressCollection();
MailAddress addressToDelete = new MailAddress("address", true);
// addressToDelete.Id.EWSId = "member's id";
membersToDelete.addMailAddress(addressToDelete);
client.addToDistributionList(distributionList, membersToDelete);
מחיקת רשימת הפצה פרטית
קטע הקוד הבא מציג כיצד למחוק רשימת הפצה פרטית.
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
ExchangeDistributionList[] distributionLists = client.listDistributionLists();
client.deleteDistributionList(distributionLists[0], true);
מחיקה ללא רישום
קוד הדוגמא הבא מראה לך כיצד למחוק ללא רישום.
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
ExchangeDistributionList distributionList = new ExchangeDistributionList();
distributionList.setId("list's id");
client.deleteDistributionList(distributionList, true);