Outlook कैलेंडर आइटम्स के साथ काम करना

MapiCalendar के साथ काम करना

Aspose.Email का MapiCalendar क्लास विभिन्न प्रॉपर्टीज़ सेट करने के लिए मेथड्स और एट्रिब्यूट्स प्रदान करती है। यह लेख कोड उदाहरण प्रदान करता है:

कैलेंडर आइटम बनाना और सेव करना

निम्नलिखित कोड स्निपेट दिखाता है कि कैलेंडर आइटम को ICS फॉर्मेट में कैसे बनाएं और सहेजें।

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "outlook/";

Calendar cal = Calendar.getInstance();
cal.set(2012, Calendar.OCTOBER, 2, 13, 0, 0);
Date startDate = cal.getTime();
cal.set(2012, Calendar.OCTOBER, 2, 14, 0, 0);
Date endDate = cal.getTime();

MapiCalendar calendar = new MapiCalendar("LAKE ARGYLE WA 6743", 
                                         "Appointment", 
                                         "This is a very important meeting :)", 
                                         startDate, 
                                         endDate);

calendar.save(dataDir + "CalendarItem_out.ics", AppointmentSaveFormat.Ics);

कैलेंडर आइटम को MSG के रूप में सेव करना

निम्नलिखित कोड स्निपेट दिखाता है कि कैलेंडर आइटम को MSG के रूप में कैसे सहेजा जाए।

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
calendar.save(dataDir + "CalendarItemAsMSG_out.Msg", AppointmentSaveFormat.Msg);

कैलेंडर आइटम को ICS में सेव करते समय प्रोडक्ट ID सेट करना

यह ProductIdentifier की प्रॉपर्टी MapiCalendarIcsSaveOptions क्लास का उपयोग MAPI कैलेंडर आइटम को iCalendar (ICS) फाइल में सहेजने के लिए किया जाता है, जो मूल तिथि और समय जानकारी और एक कस्टम प्रोडक्ट आइडेंटिफ़ायर को संरक्षित रखता है। यह प्रॉपर्टी उस प्रोडक्ट के आइडेंटिफ़ायर को निर्दिष्ट करती है जिसने iCalendar ऑब्जेक्ट बनाया।

निम्नलिखित कोड उदाहरण दिखाता है कि MAPI कैलेंडर ऑब्जेक्ट में iCalendar (ICS) डेटा के साथ कैसे काम किया जाए:

MapiCalendarIcsSaveOptions icsSaveOptions = new MapiCalendarIcsSaveOptions();
icsSaveOptions.setKeepOriginalDateTimeStamp(true);
icsSaveOptions.setProductIdentifier("Foo Ltd");

mapiCalendar.save("my.ics", icsSaveOptions);

कैलेंडर में डिस्प्ले रिमाइंडर जोड़ना

निम्नलिखित कोड स्निपेट दिखाता है कि कैलेंडर में डिस्प्ले रिमाइंडर कैसे जोड़ें।

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "outlook/";
Calendar jCalendar = Calendar.getInstance();
jCalendar.add(Calendar.HOUR, 1);
Date startDate = jCalendar.getTime();
Date endDate = jCalendar.getTime();

MailAddressCollection attendees = new MailAddressCollection();
attendees.addItem(new MailAddress("attendee@domain.com", "Attendee"));
// Create Appointment
Appointment app = new Appointment("Home", 
                                  startDate, 
                                  endDate, 
                                  new MailAddress("organizer@domain.com", "Organizer"), 
                                  attendees);
MailMessage msg = new MailMessage();
msg.addAlternateView(app.requestApointment());
MapiMessage mapi = MapiMessage.fromMailMessage(msg);
MapiCalendar calendar = (MapiCalendar) mapi.toMapiMessageItem();

// Set calendar Properties
calendar.setReminderSet(true);
calendar.setReminderDelta(5); // 45 min before start of event

String savedFile = (dataDir + "calendarWithDisplayReminder.ics");
calendar.save(savedFile, AppointmentSaveFormat.Ics);

कैलेंडर में ऑडियो रिमाइंडर जोड़ना

निम्नलिखित कोड स्निपेट दिखाता है कि कैलेंडर में ऑडियो रिमाइंडर कैसे जोड़ें।

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "outlook/";
Calendar jCalendar = Calendar.getInstance();
jCalendar.add(Calendar.HOUR, 1);
Date startDate = jCalendar.getTime();
Date endDate = jCalendar.getTime();

MailAddressCollection attendees = new MailAddressCollection();
attendees.addItem(new MailAddress("attendee@domain.com", "Attendee"));

Appointment app = new Appointment("Home", 
                                  startDate, 
                                  endDate, 
                                  new MailAddress("organizer@domain.com", "Organizer"), 
                                  attendees);

MailMessage msg = new MailMessage();
msg.addAlternateView(app.requestApointment());
MapiMessage mapi = MapiMessage.fromMailMessage(msg);
MapiCalendar cal = (MapiCalendar) mapi.toMapiMessageItem();

cal.setReminderSet(true);
cal.setReminderDelta(58); // 58 min before start of event
cal.setReminderFileParameter(dataDir + "Alarm01.wav");

String savedFile = dataDir + "calendarWithAudioReminder_out.ics";
cal.save(savedFile, AppointmentSaveFormat.Ics);

कैलेंडर फ़ाइलों से अटैचमेंट जोड़ें/प्राप्त करें

निम्नलिखित कोड स्निपेट दिखाता है कि कैलेंडर फ़ाइलों से अटैचमेंट कैसे जोड़ें/प्राप्त करें।

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "outlook/";
Calendar jCalendar = Calendar.getInstance();
jCalendar.add(Calendar.HOUR, 1);
Date startDate = jCalendar.getTime();
Date endDate = jCalendar.getTime();

String[] files = new String[3];
files[0] = "attachment_1.doc";
files[1] = "download.png";
files[2] = "Desert.jpg";

MailAddressCollection attendees = new MailAddressCollection();
attendees.addItem(new MailAddress("attendee@domain.com", "Attendee"));

Appointment app1 = new Appointment("Home", 
                                   startDate, 
                                   endDate, 
                                   new MailAddress("organizer@domain.com", "Organizer"), 
                                   attendees);
for (String file : files) {
    app1.getAttachments().addItem(new Attachment(dataDir + file));
}

app1.save(dataDir + "appWithAttachments_out.ics", AppointmentSaveFormat.Ics);

Appointment app2 = Appointment.load(dataDir + "appWithAttachments_out.ics");
System.out.println(app2.getAttachments().size());
for (Attachment att : app2.getAttachments())
    System.out.println(att.getName());

मीटिंग अनुरोध से प्राप्तकर्ताओं की स्थिति

निम्नलिखित कोड स्निपेट दिखाता है कि मीटिंग अनुरोध से प्राप्तकर्ताओं की स्थिति कैसे प्राप्त करें।

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
String fileName = "outlook/test.msg";

MapiMessage message = MapiMessage.fromFile(fileName);
for (MapiRecipient recipient : message.getRecipients()) {
    System.out.println(recipient.getRecipientTrackStatus());
}

कैलेंडर अपॉइंटमेंट की स्थिति स्पष्ट रूप से सेट करें

Aspose.Email आपको किसी की स्थिति सेट करने की अनुमति देता है MapiCalendar ऑब्जेक्ट स्पष्ट रूप से, डिफ़ॉल्ट व्यवहार को ओवरराइड करके। यह setStateForced विधि कैलेंडर इवेंट की स्थितियों पर बेहतर नियंत्रण प्रदान करती है, विशेष रूप से प्राप्त मीटिंग अनुरोधों को संभालते समय। डिफ़ॉल्ट रूप से, जब मीटिंग बनाई जाती है, उसकी स्थिति होती है MapiCalendarState.Meeting. जब प्राप्तकर्ता के इनबॉक्स में प्राप्त होता है, तो यह स्वतः बदल जाता है MapiCalendarState.Received, और इसका मैसेज क्लास अपडेट किया गया है IPM.Schedule.Meeting.Request. उपयोग करके SetStateForced मैन्युअली स्थिति को Received सेट करने की अनुमति देता है, जो कैलेंडर को MSG फ़ाइल के रूप में सहेजते समय आयोजक की जानकारी को संरक्षित रखने में उपयोगी हो सकता है। हालांकि, यह मीटिंग को उचित रूप से फ़ॉरवर्ड या पुनः भेजने से रोक सकता है।

निम्नलिखित कोड उदाहरण आपको इस सुविधा को लागू करने में मदद करेगा:

Calendar c = Calendar.getInstance();
c.set(2024, Calendar.MAY, 10, 12, 30, 0);
Date startDate = c.getTime();
c.set(2024, Calendar.MAY, 10, 13, 30, 0);
Date endDate = c.getTime();
MapiCalendar appointment = new MapiCalendar(
        "LAKE ARGYLE WA 6743",
        "Appointment",
        "This is a very important meeting :)",
        startDate,
        endDate);

MapiElectronicAddress organizer = new MapiElectronicAddress();
organizer.setEmailAddress("test@aaa.com");
organizer.setDisplayName("test display Name");
appointment.setOrganizer(organizer);

appointment.setStateForced(MapiCalendarState.Meeting | MapiCalendarState.Received);

appointment.save("appointment.msg", AppointmentSaveFormat.Msg);

मानक टाइमज़ोन से MapiCalendarTimeZone बनाएं

निम्नलिखित कोड स्निपेट दिखाता है कि कैसे बनाएँ MapiCalendarTimeZone मानक टाइमज़ोन से।

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
MapiCalendarTimeZone timeZone = new MapiCalendarTimeZone("Eastern Standard Time");

बनाए गए अपॉइंटमेंट के साथ रिमाइंडर सेट करना

जब अपॉइंटमेंट बनाया जाता है, तो एक रिमाइंडर जोड़ा जा सकता है। ये अलार्म विभिन्न मानदंडों पर आधारित ट्रिगर हो सकते हैं जैसे शेड्यूल शुरू होने से n मिनट पहले, n अंतराल पर n बार दोहराना। विभिन्न टैगों का उपयोग करके इन ट्रिगर्स को अपॉइंटमेंट के भीतर BEGIN:VALARM और END:VALARM द्वारा घेराए गए स्क्रिप्ट में बनाया जा सकता है। अपॉइंटमेंट पर रिमाइंडर सेट करने के कई वैरिएंट्स होते हैं।

टैग जोड़कर रिमाइंडर सेट करना

निम्नलिखित कोड स्निपेट दिखाता है कि टैग जोड़कर रिमाइंडर कैसे सेट किया जाए।

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = RunExamples.getDataDir_Outlook();
long MIN_MS = 60 * 1000;
long HR_MS = 60 * MIN_MS;
long DAY_MS = 24 * HR_MS;

String location = "Meeting Location: Room 5";
Date startDate = getDate(1997, 3, 18, 18, 30, 00);
Date endDate = getDate(1997, 3, 18, 19, 30, 00);
MailAddress organizer = new MailAddress("aaa@amail.com", "Organizer");
MailAddressCollection attendees = new MailAddressCollection();
attendees.addItem(new MailAddress("bbb@bmail.com", "First attendee"));

Appointment target = new Appointment(location, startDate, endDate, organizer, attendees);

// Audio alarm that will sound at a precise time and
// Repeat 4 more times at 15 minute intervals:
AppointmentReminder audioReminder = new AppointmentReminder();
audioReminder.setTrigger(new ReminderTrigger(getDate(1997, 3, 17, 13, 30, 0)));
audioReminder.setRepeat(4);
audioReminder.setDuration(new ReminderDuration(15 * MIN_MS));
audioReminder.setAction(ReminderAction.Audio);
ReminderAttachment attach = new ReminderAttachment(new URI("ftp://Host.com/pub/sounds/bell-01.aud"));
audioReminder.getAttachments().addItem(attach);
target.getReminders().addItem(audioReminder);


// Display alarm that will trigger 30 minutes before the
// Scheduled start of the event it is
// Associated with and will repeat 2 more times at 15 minute intervals:
AppointmentReminder displayReminder = new AppointmentReminder();
ReminderDuration dur = new ReminderDuration(-30 * MIN_MS);
displayReminder.setTrigger(new ReminderTrigger(dur, ReminderRelated.Start));
displayReminder.setRepeat(2);
displayReminder.setDuration(new ReminderDuration(15 * MIN_MS));
displayReminder.setAction(ReminderAction.Display);
displayReminder.setDescription("Breakfast meeting with executive team at 8:30 AM EST");
target.getReminders().addItem(displayReminder);

// Email alarm that will trigger 2 days before the
// Scheduled due date/time. It does not
// Repeat. The email has a subject, body and attachment link.
AppointmentReminder emailReminder = new AppointmentReminder();
ReminderDuration dur1 = new ReminderDuration(-2 * DAY_MS);
emailReminder.setTrigger(new ReminderTrigger(dur1, ReminderRelated.Start));
ReminderAttendee attendee = new ReminderAttendee("john_doe@host.com");
emailReminder.getAttendees().addItem(attendee);
emailReminder.setAction(ReminderAction.Email);
emailReminder.setSummary("REMINDER: SEND AGENDA FOR WEEKLY STAFF MEETING");
emailReminder.setDescription("A draft agenda needs to be sent out to the attendees to the weekly managers meeting (MGR-LIST). Attached is a pointer the document template for the agenda file.");
ReminderAttachment attach1 = new ReminderAttachment(new URI("http://Host.com/templates/agenda.doc"));
emailReminder.getAttachments().addItem(attach1);
target.getReminders().addItem(emailReminder);

// Procedural alarm that will trigger at a precise date/time
// And will repeat 23 more times at one hour intervals. The alarm will
// Invoke a procedure file.
AppointmentReminder procReminder = new AppointmentReminder();
procReminder.setTrigger(new ReminderTrigger(getDate(1998, 1, 1, 5, 0, 0)));
procReminder.setRepeat(23);
procReminder.setDuration(new ReminderDuration(1 * DAY_MS));
procReminder.setAction(ReminderAction.Procedure);
ReminderAttachment attach2 = new ReminderAttachment(new URI("ftp://Host.com/novo-procs/felizano.exe"));
procReminder.getAttachments().addItem(attach2);
target.getReminders().addItem(procReminder);
target.save(dataDir + "savedFile_out.ics");

HTML बॉडी के साथ अपॉइंटमेंट EML को MSG में परिवर्तित करें

वर्ज़न 19.3 से, Aspose.Email यह क्षमता प्रदान करता है कि अपॉइंटमेंट EML को MSG में परिवर्तित किया जा सके जबकि अपॉइंटमेंट के HTML बॉडी को बरकरार रखा जाए। Aspose.Email एक MapiConversionOptions.ForcedRtfBodyForAppointment प्रॉपर्टी जिसकी डिफ़ॉल्ट वैल्यू true. है। जब वैल्यू MapiConversionOptions.ForcedRtfBodyForAppointment यदि true पर सेट किया जाता है, तो अपॉइंटमेंट बॉडी RTF फॉर्मेट में परिवर्तित हो जाता है। अपॉइंटमेंट बॉडी फॉर्मेट को HTML फॉर्मेट में रखने के लिए, मान सेट करें MapiConversionOptions.ForcedRtfBodyForAppointment को false.

निम्नलिखित उदाहरण उपयोग को दर्शाता है MapiConversionOptions.ForcedRtfBodyForAppointment ऐपॉइंटमेंट बॉडी फॉर्मेट को HTML फॉर्मेट में रखने के लिए प्रॉपर्टी।

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the File directory.
String dataDir = "outlook/";

MailMessage mailMessage = MailMessage.load(dataDir + "TestAppointment.eml");

MapiConversionOptions conversionOptions = new MapiConversionOptions();
conversionOptions.setFormat(OutlookMessageFormat.Unicode);

// default value for ForcedRtfBodyForAppointment is true
conversionOptions.setForcedRtfBodyForAppointment(false);

MapiMessage mapiMessage = MapiMessage.fromMailMessage(mailMessage, conversionOptions);

if (mapiMessage.getBodyType() == BodyContentType.Html) {
    System.out.println("Body Type: Html");
} else if (mapiMessage.getBodyType() == BodyContentType.Rtf) {
    System.out.println("Body Type: Rtf");
}

mapiMessage.save(dataDir + "TestAppointment_out.msg");