Exchange सर्वर पर कैलेंडर आइटम्स के साथ काम करना
मीटिंग अनुरोध भेजना
यह लेख दिखाता है कि Exchange Web Services और Aspose.Email का उपयोग करके कई प्राप्तकर्ताओं को मीटिंग अनुरोध कैसे भेजा जाए।
- Appointment क्लास का उपयोग करके एक मीटिंग अनुरोध बनाएं और स्थान, समय और उपस्थितियों को सेट करें।
- MailMessage क्लास का एक इंस्टेंस बनाएं और MailMessage.addAlternateView() मेथड का उपयोग करके अपॉइंटमेंट सेट करें।
- Exchange सर्वर से कनेक्ट करें और send(MailMessage) मेथड का उपयोग करके मीटिंग अनुरोध भेजें।
यह EWSClient क्लास का उपयोग Exchange Web Services (EWS) सपोर्ट वाले Exchange सर्वर से कनेक्ट करने के लिए किया जा सकता है। इसके लिए सर्वर को Exchange Server 2007 या उससे नए संस्करण का होना आवश्यक है। नीचे कोड स्निपेट दर्शाता है कि EWS का उपयोग करके मीटिंग अनुरोध कैसे भेजें।
try {
// Create instance of IEWSClient class by giving credentials
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
Calendar c = Calendar.getInstance();
c.add(Calendar.HOUR_OF_DAY, 1);
Date startTime = c.getTime();
c.add(Calendar.MINUTE, 90);
Date endTime = c.getTime();
// Create the meeting request
Appointment app = new Appointment("meeting request", startTime, endTime, MailAddress.to_MailAddress("administrator@test.com"),
MailAddressCollection.to_MailAddressCollection("bob@test.com"));
app.setSummary("meeting request summary");
app.setDescription("description");
c = Calendar.getInstance();
c.add(Calendar.DATE, 5);
RecurrencePattern pattern = new DailyRecurrencePattern(c.getTime());
app.setRecurrence(pattern);
// Create the message and set the meeting request
MailMessage msg = new MailMessage();
msg.setFrom(MailAddress.to_MailAddress("administrator@test.com"));
msg.setTo(MailAddressCollection.to_MailAddressCollection("bob@test.com"));
msg.isBodyHtml(true);
msg.setHtmlBody("<h3>HTML Heading</h3><p>Email Message detail</p>");
msg.setSubject("meeting request");
msg.addAlternateView(app.requestApointment(0));
// send the appointment
client.send(msg);
System.out.println("Appointment request sent");
} catch (java.lang.RuntimeException ex) {
System.out.println(ex.getMessage());
}
EWS का उपयोग करके कैलेंडर आइटम्स के साथ काम करना
Aspose.Email Exchange Web Service (EWS) क्लाइंट का उपयोग करके अपॉइंटमेंट्स को जोड़ने, अपडेट करने और रद्द करने की क्षमता प्रदान करता है। IEWSClients createAppointment, updateAppointment, and cancelAppointment मेथड्स EWS का उपयोग करके कैलेंडर आइटम्स को हेरफ़ेर करने की अनुमति देते हैं। यह लेख कैलेंडर आइटम्स के साथ काम करने का विस्तृत कोड नमूना प्रदान करता है। नीचे का कोड नमूना दर्शाता है कि कैसे:
- एक अपॉइंटमेंट बनाएँ।
- एक अपॉइंटमेंट को अपडेट करें।
- एक अपॉइंटमेंट को हटाएँ/रद्द करें।
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "your.username", "your.Password");
Calendar c = Calendar.getInstance();
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
Date startTime = c.getTime();
c.add(Calendar.HOUR_OF_DAY, 1);
Date endTime = c.getTime();
String timeZone = "America/New_York";
Appointment app = new Appointment("Room 112", startTime, endTime, MailAddress.to_MailAddress("organizeraspose-email.test3@domain.com"),
MailAddressCollection.to_MailAddressCollection("attendee@gmail.com"));
app.setTimeZone(timeZone);
app.setSummary("NETWORKNET-34136" + UUID.randomUUID().toString());
app.setDescription("NETWORKNET-34136 Exchange 2007/EWS: Provide support for Add/Update/Delete calendar items");
String uid = client.createAppointment(app);
Appointment fetchedAppointment1 = client.fetchAppointment(uid);
app.setLocation("Room 115");
app.setSummary("New summary for " + app.getSummary());
app.setDescription("New Description");
client.updateAppointment(app);
Appointment[] appointments1 = client.listAppointments();
System.out.println("Total Appointments: " + appointments1.length);
Appointment fetchedAppointment2 = client.fetchAppointment(uid);
System.out.println("Summary: " + fetchedAppointment2.getSummary());
System.out.println("Location: " + fetchedAppointment2.getLocation());
System.out.println("Description: " + fetchedAppointment2.getDescription());
client.cancelAppointment(app);
Appointment[] appointments2 = client.listAppointments();
System.out.println("Total Appointments: " + appointments2.length);
निर्दिष्ट तिथि सीमा के भीतर पुनरावर्ती कैलेंडर आइटम्स को लौटाएँ
Aspose.Email EWSClient StartDate और EndDate द्वारा निर्दिष्ट रेंज के भीतर पुनरावर्ती कैलेंडर आइटम्स को लौटाने का समर्थन करता है। The AppointmentQueryBuilder.setCalendarView(Date startDate, Date endDate, int maxEntriesReturned) विधि, यदि CalendarView निर्दिष्ट किया गया है, तो StartDate और EndDate द्वारा निर्दिष्ट रेंज के भीतर एकल कैलेंडर आइटम्स और पुनरावर्ती कैलेंडर आइटम्स की घटनाओं की सूची लौटाता है। maxEntriesReturned पैरामीटर अधिकतम परिणामों की संख्या दर्शाता है। (सभी परिणामों के लिए मान <= 0)।
ExchangeQueryBuilder builder = new ExchangeQueryBuilder();
builder.getAppointment().setCalendarView(startDate, endDate, -1);
Appointment[] appointments = client.listAppointments(builder.getQuery());
पेजिंग सपोर्ट के साथ अपॉइंटमेंट्स की सूची बनाना
ListAppointments मेथड द्वारा प्रकाशित IEWSClient API Exchange सर्वर से सभी अपॉइंटमेंट्स की पूरी सूची प्राप्त करती है। यदि सर्वर पर बड़ी संख्या में अपॉइंटमेंट्स हैं तो इसमें समय लग सकता है। API ओवरलोडेड मेथड्स प्रदान करती है listAppointments विधि जो ऑपरेशन को पेजिंग समर्थन देती है। इसे क्वेरी फीचर के साथ विभिन्न संयोजनों में भी उपयोग किया जा सकता है। Exchange Server से पेजिंग समर्थन के साथ अपॉइंटमेंट्स सूचीबद्ध करने के लिए निम्न ओवरलोडेड मेथड उपलब्ध हैं।
- AppointmentCollection IEWSClient.listAppointments(int itemsPerPage).
- AppointmentCollection IEWSClient.listAppointments(String folderUri, int itemsPerPage).
- AppointmentCollection IEWSClient.listAppointments(MailQuery query, int itemsPerPage).
- AppointmentCollection IEWSClient.listAppointments(String folderUri, MailQuery query, int itemsPerPage).
- AppointmentCollection IEWSClient.listAppointments(int itemsPerPage, int itemOffset).
- AppointmentCollection IEWSClient.listAppointments(String folderUri, int itemsPerPage, int itemOffset).
- AppointmentCollection IEWSClient.listAppointments(MailQuery query, int itemsPerPage, int itemOffset).
- AppointmentCollection IEWSClient.listAppointments(String folderUri, MailQuery query, int itemsPerPage, int itemOffset).
निम्न कोड स्निपेट दर्शाता है कि पेजिंग समर्थन के साथ अपॉइंटमेंट्स की सूची कैसे बनाएं।
IEWSClient client = EWSClient.getEWSClient("exchange.domain.com", "username", "password");
try {
try {
Appointment[] appts = client.listAppointments();
System.out.println(appts.length);
Calendar c = Calendar.getInstance();
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
int appNumber = 10;
Map<String, Appointment> appointmentsDict = new HashMap<String, Appointment>();
for (int i = 0; i < appNumber; i++) {
c.set(Calendar.HOUR_OF_DAY, i + 1);
Date startTime = c.getTime();
c.set(Calendar.HOUR_OF_DAY, i + 2);
Date endTime = c.getTime();
String timeZone = "America/New_York";
Appointment appointment = new Appointment("Room 112", startTime, endTime, MailAddress.to_MailAddress("from@domain.com"),
MailAddressCollection.to_MailAddressCollection("to@domain.com"));
appointment.setTimeZone(timeZone);
appointment.setSummary("NETWORKNET-35157_3 - " + UUID.randomUUID().toString());
appointment.setDescription("EMAILNET-35157 Move paging parameters to separate class");
String uid = client.createAppointment(appointment);
appointmentsDict.put(uid, appointment);
}
AppointmentCollection totalAppointmentCol = AppointmentCollection.to_AppointmentCollection(client.listAppointments());
///// LISTING APPOINTMENTS WITH PAGING SUPPORT ///////
int itemsPerPage = 2;
List<AppointmentPageInfo> pages = new ArrayList<AppointmentPageInfo>();
AppointmentPageInfo pagedAppointmentCol = client.listAppointmentsByPage(itemsPerPage);
System.out.println(pagedAppointmentCol.getItems().size());
pages.add(pagedAppointmentCol);
while (!pagedAppointmentCol.getLastPage()) {
pagedAppointmentCol = client.listAppointmentsByPage(itemsPerPage, pagedAppointmentCol.getPageOffset() + 1);
pages.add(pagedAppointmentCol);
}
int retrievedItems = 0;
// foreach to while statements conversion
for (AppointmentPageInfo folderCol : pages) {
retrievedItems += folderCol.getItems().size();
}
} finally {
}
} finally {
client.dispose();
}
Exchange Server पर सेकेंडरी कैलेंडर फ़ोल्डर में इवेंट जोड़ना
Aspose.Email API आपको Exchange Server पर एक सेकेंडरी कैलेंडर फ़ोल्डर बनाने की अनुमति देता है, उपयोग करके IEWSClient. अपॉइंटमेंट्स को फिर सेकेंडरी कैलेंडर से जोड़ा, अपडेट या रद्द किया जा सकता है, उपयोग करके createAppointment, updateAppointment और cancelAppointment मेथड्स। नीचे कोड नमूने में इस फीचर की कार्यक्षमता दिखाने के लिए निम्न API मेथड्स और प्रॉपर्टीज़ का उपयोग किया गया है। कृपया ध्यान दें कि यह फीचर Aspose.Email for Java 6.5.0 और बाद के संस्करणों में समर्थित है।
- मेथड IEWSClient.cancelAppointment(Appointment, String).
- मेथड IEWSClient.cancelAppointment(String, String).
- मेथड IEWSClient.createAppointment(Appointment, String).
- मेथड IEWSClient.createFolder(String, String, ExchangeFolderPermissionCollection, String).
- मेथड IEWSClient.fetchAppointment(String, String).
- मेथड IEWSClient.updateAppointment(Appointment, String).
- प्रॉपर्टी IEWSClient.CurrentCalendarFolderUri.
निम्न कोड स्निपेट दर्शाता है कि एक्सचेंज सर्वर पर सेकेंडरी कैलेंडर फ़ोल्डर में इवेंट कैसे जोड़ें।
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "your.username", "your.Password");
try {
try {
// Create an appointmenta that will be added to secondary calendar folder
Calendar c = Calendar.getInstance();
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
Date startTime = c.getTime();
c.add(Calendar.HOUR_OF_DAY, 1);
Date endTime = c.getTime();
String timeZone = "America/New_York";
Appointment[] listAppointments;
Appointment appointment = new Appointment("Room 121", startTime, endTime, MailAddress.to_MailAddress("from@domain.com"),
MailAddressCollection.to_MailAddressCollection("attendee@domain.com"));
appointment.setTimeZone(timeZone);
appointment.setSummary("EMAILNET-35198 - " + UUID.randomUUID().toString());
appointment.setDescription("EMAILNET-35198 Ability to add event to Secondary Calendar of Office 365");
// Verify that the new folder has been created
ExchangeFolderInfoCollection calendarSubFolders = client.listSubFolders(client.getMailboxInfo().getCalendarUri());
String getfolderName;
String setFolderName = "New Calendar";
boolean alreadyExits = false;
// Verify that the new folder has been created already exits or not
for (int i = 0; i < calendarSubFolders.size(); i++) {
getfolderName = calendarSubFolders.get_Item(i).getDisplayName();
if (getfolderName.equals(setFolderName)) {
alreadyExits = true;
}
}
if (alreadyExits) {
System.out.println("Folder Already Exists");
} else {
// Create new calendar folder
client.createFolder(client.getMailboxInfo().getCalendarUri(), setFolderName, null, "IPF.Appointment");
System.out.println(calendarSubFolders.size());
// Get the created folder URI
String newCalendarFolderUri = calendarSubFolders.get_Item(0).getUri();
// appointment api with calendar folder uri
// Create
client.createAppointment(appointment, newCalendarFolderUri);
appointment.setLocation("Room 122");
// update
client.updateAppointment(appointment, newCalendarFolderUri);
// list
listAppointments = client.listAppointments(newCalendarFolderUri);
// list default calendar folder
listAppointments = client.listAppointments(client.getMailboxInfo().getCalendarUri());
// Cancel
client.cancelAppointment(appointment, newCalendarFolderUri);
listAppointments = client.listAppointments(newCalendarFolderUri);
// appointment api with context current calendar folder uri
client.setCurrentCalendarFolderUri(newCalendarFolderUri);
// Create
client.createAppointment(appointment);
appointment.setLocation("Room 122");
// update
client.updateAppointment(appointment);
// list
listAppointments = client.listAppointments();
// list default calendar folder
listAppointments = client.listAppointments(client.getMailboxInfo().getCalendarUri());
// Cancel
client.cancelAppointment(appointment);
listAppointments = client.listAppointments();
}
} finally {
}
} finally {
client.dispose();
}
कैलेंडर इनवाइटेशन शेयर करना
Microsoft Exchange सर्वर कैलेंडर शेयर करने की क्षमता देता है, जिसमें समान Exchange सर्वर पर पंजीकृत अन्य उपयोगकर्ताओं को कैलेंडर इनवाइटेशन भेजे जा सकते हैं। Aspose.Email API भी EWS API का उपयोग करके कैलेंडर शेयर करने की वही सुविधा प्रदान करता है।
final IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
try {
// delegate calendar access permission
ExchangeDelegateUser delegateUser = new ExchangeDelegateUser("sharingfrom@domain.com", ExchangeDelegateFolderPermissionLevel.NotSpecified);
delegateUser.getFolderPermissions().setCalendarFolderPermissionLevel(ExchangeDelegateFolderPermissionLevel.Reviewer);
client.delegateAccess(delegateUser, "sharingfrom@domain.com");
// Create invitation
MapiMessage mapiMessage = client.createCalendarSharingInvitationMessage("sharingfrom@domain.com");
MailConversionOptions options = new MailConversionOptions();
options.setConvertAsTnef(true);
MailMessage mail = mapiMessage.toMailMessage(options);
client.send(mail);
} finally {
client.dispose();
}
कैलेंडर आइटम्स से विस्तारित विशेषताओं की जानकारी प्राप्त करना
IEWSClient client = EWSClient.getEWSClient("https://exchange.office365.com/Exchange.asmx", "username", "password");
java.util.List<String> uriList = java.util.Arrays.asList(client.listItems(client.getMailboxInfo().getCalendarUri()));
// Define the Extended Attribute Property Descriptor for searching purpose
// In this case, we have a K1 Long named property for Calendar item
UUID uuid = UUID.fromString("00020329-0000-0000-C000-000000000046");
PropertyDescriptor propertyDescriptor = new PidNamePropertyDescriptor("K1", PropertyDataType.Integer32, uuid);
java.util.List<PropertyDescriptor> propertyDescriptors = java.util.Arrays.asList(new PropertyDescriptor[] { propertyDescriptor });
IGenericList<MapiCalendar> mapiCalendarList = client.fetchMapiCalendar(uriList, propertyDescriptors);
for (MapiCalendar cal : mapiCalendarList) {
for (MapiNamedProperty namedProperty : (Iterable<MapiNamedProperty>) cal.getNamedProperties().getValues()) {
System.out.println(namedProperty.getNameId() + " = " + namedProperty.getInt32());
}
}