Aspose.Email.Outlook के साथ संदेश फ़ाइलों का प्रबंधन

MSG को MIME संदेश में परिवर्तित करना

Aspose.Email API MSG फ़ाइलों को MIME संदेशों में परिवर्तित करने की क्षमता प्रदान करता है, उपयोग करके toMailMessage विधि।

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
MapiMessage msg = new MapiMessage(
                            "sender@test.com",
                            "recipient1@test.com; recipient2@test.com",
                            "Test Subject",
                            "This is a body of message.");
MailConversionOptions options = new MailConversionOptions();
options.setConvertAsTnef(true);
MailMessage mail = msg.toMailMessage(options);

MSG को EML में परिवर्तित करते समय RTF बॉडी को संरक्षित करना

API MSG को EML में परिवर्तित करते समय RTF बॉडी को संरक्षित करने के लिए निम्नलिखित मेथड्स प्रदान करता है:

  • MsgLoadOptions.PreserveRtfContent - MailMessage में rtf बॉडी को रखने का संकेत देने वाला मान प्राप्त करता है या सेट करता है।
  • MailConversionOptions.PreserveRtfContent - MailMessage में rtf बॉडी को रखने का संकेत देने वाला मान प्राप्त करता है या सेट करता है।

निम्नलिखित कोड नमूने दिखाते हैं कि MailMessage में rtf बॉडी को कैसे रखा जाए:

MsgLoadOptions options = new MsgLoadOptions();
options.setPreserveRtfContent(true);
MailMessage message = MailMessage.load("fileName", options);
MapiMessage mapi = MapiMessage.load("fileName");
MailConversionOptions options = new MailConversionOptions();
options.setPreserveRtfContent(true);
MailMessage message = mapi.toMailMessage(options);

MSG को MHTML में परिवर्तित करते समय श्रेणी हेडर को संरक्षित करना

Aspose.Email API संदेश को MHTML में परिवर्तित करते समय एक श्रेणी हेडर जोड़ने की क्षमता प्रदान करता है। यह सुविधा द्वारा निर्दिष्ट है MhtSaveOptions class को अतिरिक्त विकल्प के रूप में उपयोग किया जाता है जब MailMessage को Mhtml प्रारूप में सहेजा जाता है।

निम्नलिखित कोड नमूना दर्शाता है कि कैसे MapiMessage ऑब्जेक्ट से MHT (MHTML) फ़ाइल बनाई जाए, MhtSaveOptions का उपयोग करके MHT फ़ाइल के फॉर्मेट और हेडर को अनुकूलित किया जाए, ईमेल संदेश के लिए श्रेणियां सेट की जाएँ और फिर फ़ाइल को सहेजने से पहले फ़ॉर्मेट टेम्पलेट और रेंडरिंग हेडर को संशोधित किया जाए।

 MapiMessage msg = new MapiMessage("from@aaa.com", "to@aaa.com", "subj", "body");

msg.setCategories(new String[] { "Urgently", "Important" });

MhtSaveOptions saveOptions = new MhtSaveOptions();

saveOptions.getFormatTemplates().set_Item(MhtTemplateName.CATEGORIES,

    saveOptions.getFormatTemplates().get_Item(MhtTemplateName.CATEGORIES).replace("Categories", "Les catégories"));

saveOptions.getRenderingHeaders().add(MhtTemplateName.CATEGORIES);

msg.save("fileName.mhtml", saveOptions);

Outlook टेम्पलेट फ़ाइल (.OFT) पढ़ना और लिखना

Outlook टेम्पलेट बहुत उपयोगी होते हैं जब आप समान ईमेल संदेश को बार‑बार भेजना चाहते हैं। हर बार शुरू से संदेश तैयार करने के बजाय, पहले Outlook में संदेश तैयार करें और उसे Outlook टेम्पलेट (OFT) के रूप में सहेजें। इसके बाद, जब भी आपको संदेश भेजना हो, आप टेम्पलेट से बना सकते हैं, जिससे बॉडी या विषय पंक्ति में वही पाठ लिखने, फॉर्मेट सेट करने आदि में समय बचता है। Aspose.Email MailMessage class का उपयोग Outlook टेम्पलेट (OFT) फ़ाइल को लोड और पढ़ने के लिए किया जा सकता है। एक बार Outlook टेम्पलेट को एक instance में लोड किया जाने पर MailMessage class, आप प्रेषक, प्राप्तकर्ता, बॉडी, विषय और अन्य गुण अपडेट कर सकते हैं। गुणों को अपडेट करने के बाद:

  • ईमेल भेजें उपयोग करके SmtpClient class या
  • संदेश को MSG के रूप में सहेजें और Microsoft Outlook का उपयोग करके आगे के अपडेट/मान्यताएं करें।

नीचे दिए गए कोड नमूनों में, हम:

  1. टेम्पलेट को उपयोग करके लोड करें MailMessage क्लास।
  2. कुछ गुणों को अपडेट करें।
  3. संदेश को MSG प्रारूप में सहेजें।

निम्नलिखित कोड स्निपेट दिखाता है कि OFT फ़ाइल को लोड करें, संदेश को अपडेट करें और इसे MSG प्रारूप में सहेजें।

// 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/";

// Load the Outlook template (OFT) file in MailMessage's instance
MailMessage message = MailMessage.load(dataDir + "sample.oft", new MsgLoadOptions());

// Set the sender and recipients information
String senderDisplayName = "John";
String senderEmailAddress = "john@abc.com";
String recipientDisplayName = "William";
String recipientEmailAddress = "william@xzy.com";

message.setSender(new MailAddress(senderEmailAddress, senderDisplayName));
message.getTo().addMailAddress(new MailAddress(recipientEmailAddress, recipientDisplayName));
message.setHtmlBody(message.getHtmlBody().replace("DisplayName", "<b>" + recipientDisplayName + "</b>"));

// Set the name, location and time in email body
String meetingLocation = "<u>" + "Hall 1, Convention Center, New York, USA" + "</u>";
String meetingTime = "<u>" + "Monday, June 28, 2010" + "</u>";
message.setHtmlBody(message.getHtmlBody().replace("MeetingPlace", meetingLocation));
message.setHtmlBody(message.getHtmlBody().replace("MeetingTime", meetingTime));

// Save the message in MSG format and open in Office Outlook
MapiMessage mapimessage = MapiMessage.fromMailMessage(message);
mapimessage.setMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT);
mapimessage.save(dataDir + "ReadAndWritingOutlookTemplateFile_out.msg");

Outlook MSG फ़ाइल को टेम्पलेट के रूप में सहेजना

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

// 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/";

try (MapiMessage mapi = new MapiMessage("test@from.to", "test@to.to", "template subject", "Template body")) {
    mapi.saveAsTemplate(dataDir + "mapiToOft.msg");
}

Outlook MSG फ़ाइलों के लिए रंग श्रेणी सेट करना

एक रंग श्रेणी ईमेल संदेश को कुछ प्रकार के महत्व या वर्गीकरण के लिए चिह्नित करती है। Microsoft Outlook उपयोगकर्ताओं को ईमेल को अलग पहचानने के लिए रंग श्रेणियां सौंपने की अनुमति देता है। रंग श्रेणी को संभालने के लिए, उपयोग करें FollowUpManager. इसमें निम्नलिखित जैसे फ़ंक्शन शामिल हैं addCategory, removeCategory, clearCategories और getCategories.

  • addCategory लेता है MapiMessage और रंग श्रेणी स्ट्रिंग, उदाहरण के लिए, "Purple Category" या "Red Category" को तर्कों के रूप में।
  • removeCategory लेता है MapiMessage और वह रंग श्रेणी स्ट्रिंग जिसे संदेश से हटाया जाना है।
  • clearCategories संदेश से सभी रंग श्रेणियों को हटाने के लिए उपयोग किया जाता है।
  • getCategories किसी विशिष्ट संदेश से सभी रंग श्रेणियों को प्राप्त करने के लिए उपयोग किया जाता है।

निम्नलिखित उदाहरण नीचे दिए गए कार्यों को निष्पादित करता है:

  1. एक रंग श्रेणी जोड़ें।
  2. एक और रंग श्रेणी जोड़ें।
  3. सभी श्रेणियों की सूची प्राप्त करें।
  4. सभी श्रेणियां हटाएँ।
// 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/";

MapiMessage msg = MapiMessage.fromFile(dataDir + "message.msg");

// Add Two category
FollowUpManager.addCategory(msg, "Purple Category");
FollowUpManager.addCategory(msg, "Red Category");

// Retrieve the list of available categories
IList categories = FollowUpManager.getCategories(msg);

// Remove the specified category and then Clear all categories
FollowUpManager.removeCategory(msg, "Red Category");
FollowUpManager.clearCategories(msg);

MSG फ़ाइल से फॉलो‑अप जानकारी तक पहुँच

Aspose.Email API एक भेजे या प्राप्त संदेश से फॉलो‑अप जानकारी तक पहुँचने की क्षमता प्रदान करता है। यह संदेश फ़ाइल से पढ़ने, डिलीवरी पढ़ने रसीद और वोट परिणाम जानकारी प्राप्त कर सकता है।

पढ़ने और डिलीवरी रसीद जानकारी प्राप्त करना

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

// 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/";

MapiMessage msg = MapiMessage.fromFile(dataDir + "message.msg");
for (MapiRecipient recipient : msg.getRecipients()) {
    System.out.println("Recipient: " + recipient.getDisplayName());

    // Get the PR_RECIPIENT_TRACKSTATUS_TIME_DELIVERY property
    System.out.println("Delivery time: " + recipient.getProperties().get_Item(MapiPropertyTag.PR_RECIPIENT_TRACKSTATUS_TIME_DELIVERY).getDateTime());

    // Get the PR_RECIPIENT_TRACKSTATUS_TIME_READ property
    System.out.println("Read time" + recipient.getProperties().get_Item(MapiPropertyTag.PR_RECIPIENT_TRACKSTATUS_TIME_READ).getDateTime());
}

फ़ॉरवर्ड और रिप्लाइ संदेश बनाना

Aspose.Email API फ़ॉरवर्ड और रिप्लाइ संदेश बनाने और फ़ॉर्मेट करने की क्षमता प्रदान करता है। यह ReplyMessageBuilder और ForwardMessageBuilder API की क्लासें क्रमशः Reply और Forward संदेश बनाने के लिए उपयोग की जाती हैं। Reply या Forward संदेश को किसी भी मोड का उपयोग करके बनाया जा सकता है OriginalMessageAdditionMode enum। इस enum में निम्न मान हैं:

  • OriginalMessageAdditionMode.None - मूल संदेश को प्रतिक्रिया संदेश में शामिल नहीं किया जाता।
  • OriginalMessageAdditionMode.Attachment - मूल संदेश को प्रतिक्रिया संदेश में अटैचमेंट के रूप में शामिल किया जाता है
  • OriginalMessageAdditionMode.Textpart - मूल संदेश को प्रतिक्रिया संदेश के बॉडी में टेक्स्ट के रूप में शामिल किया जाता है

उत्तर संदेश बनाना

निम्न कोड स्निपेट दिखाता है कि उत्तर संदेश कैसे बनाया जाए।

// 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/";

MapiMessage originalMsg = MapiMessage.fromFile(dataDir + "message1.msg");
ReplyMessageBuilder builder = new ReplyMessageBuilder();

// Set ReplyMessageBuilder Properties
builder.setReplyAll(true);
builder.setAdditionMode(OriginalMessageAdditionMode.Textpart);
builder.setResponseText(
        "<p><b>Dear Friend,</b></p> I want to do is introduce my co-author and co-teacher. <p><a href=\"www.google.com\">This is a first link</a></p><p><a href=\"www.google.com\">This is a second link</a></p>");

MapiMessage replyMsg = builder.buildResponse(originalMsg);
replyMsg.save(dataDir + "reply_out.msg");

फ़ॉरवर्ड संदेश बनाना

निम्न कोड स्निपेट दिखाता है कि फ़ॉरवर्ड संदेश कैसे बनाया जाए।

// 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/";

MapiMessage originalMsg = MapiMessage.fromFile(dataDir + "message1.msg");
ForwardMessageBuilder builder = new ForwardMessageBuilder();
builder.setAdditionMode(OriginalMessageAdditionMode.Textpart);
MapiMessage forwardMsg = builder.buildResponse(originalMsg);
forwardMsg.save(dataDir + "forward_out.msg");

संदेश बदलते समय खाली तिथियों को संरक्षित करें

MapiConversionOptions.setPreserveEmptyDates(boolean) प्रॉपर्टी जो दर्शाती है कि संदेश को बदलते समय खाली तिथियों को रखना आवश्यक है या नहीं। यह API Aspose.Email 21.5 में उपलब्ध है। नीचे दिया गया कोड स्निपेट दिखाता है कि खाली तिथियों को कैसे संरक्षित किया जाए।

MailMessage mailMessage = MailMessage.load("message.eml");
System.out.println(mailMessage.getDate()); // zero date
MapiConversionOptions mco = MapiConversionOptions.getUnicodeFormat();
// keep empty dates when converting a message
mco.setPreserveEmptyDates(true);
MapiMessage mapiMessage = MapiMessage.fromMailMessage(mailMessage, mco);
System.out.println(mapiMessage.getClientSubmitTime()); // zero date
// check zero date
if (mapiMessage.getClientSubmitTime().equals(JavaHelper.ZERO_DATE))
    System.out.println("ZERO DATE");