MSG फ़ाइल को लोड करना, देखना और पार्स करना
यह विषय समझाता है कि Microsoft Outlook संदेश फ़ाइल (*.msg) को कैसे लोड किया जाए। यह MapiMessage क्लास MSG फ़ाइलों को लोड करने के लिए उपयोग की जाती है और विभिन्न परिदृश्यों के लिए कई स्थैतिक लोडिंग फ़ंक्शन प्रदान करती है। निम्नलिखित कोड स्निपेट दिखाता है कि फ़ाइल या स्ट्रीम से MSG फ़ाइलें कैसे लोड की जाएँ।
MSG फ़ाइलें लोड करना
निम्नलिखित कोड स्निपेट दिखाता है कि 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 = RunExamples.getDataDir_Outlook();
// Create an instance of MapiMessage from file
MapiMessage msg = MapiMessage.fromFile(dataDir + "message.msg");
// Get subject
System.out.println("Subject:" + msg.getSubject());
// Get from address
System.out.println("From:" + msg.getSenderEmailAddress());
// Get body
System.out.println("Body" + msg.getBody());
// Get recipients information
System.out.println("Recipient: " + msg.getRecipients());
// Get attachments
for (MapiAttachment att : msg.getAttachments())
{
System.out.println("Attachment Name: " + att.getFileName());
System.out.println("Attachment Display Name: " + att.getDisplayName());
}
निम्नलिखित कोड उदाहरण दिखाता है कि MailMessage का उपयोग करके MSG स्वरूप में संदेश कैसे लोड किया जाए।
MailMessage eml = MailMessage.load("message.msg");
ध्यान देने योग्य है कि परिणामी संदेश को EML प्रारूप में परिवर्तित किया जाता है, जिसमें एंबेडेड संदेश अटैचमेंट शामिल होते हैं। यदि आप मूल संदेश के कुछ विशिष्ट MSG फ़ॉर्मेट गुणों को संरक्षित रखना चाहते हैं, तो इस लोडिंग विधि का उपयोग न करें।
एंबेडेड संदेश अटैचमेंट्स के मूल स्वरूप को संरक्षित रखने के लिए, उपयोग करें MsgLoadOptions.PreserveEmbeddedMessageFormat प्रॉपर्टी।
MsgLoadOptions msgLoadOptions = new MsgLoadOptions();
msgLoadOptions.setPreserveEmbeddedMessageFormat(true);
MailMessage msg = MailMessage.load(stream, msgLoadOptions);
स्ट्रीम से लोड करना
निम्नलिखित कोड स्निपेट दिखाता है कि कैसे एक फ़ाइल को स्ट्रीम से लोड किया जाए।
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// Create an instance of MapiMessage from file
try (FileInputStream stream = new FileInputStream(dataDir + "message.msg"))
{
// Create an instance of MapiMessage from file
MapiMessage msg = MapiMessage.fromStream(stream);
// Get subject
System.out.println("Subject:" + msg.getSubject());
// Get from address
System.out.println("From:" + msg.getSenderEmailAddress());
// Get body
System.out.println("Body" + msg.getBody());
}
एंबेडेड EML फ़ॉर्मेट को संरक्षित रखते हुए EML को MSG में बदलना
EML फ़ाइलें लोड की जा सकती हैं MapiMessage क्लास को एक … इंस्टैंसिएट करके MailMessage ऑब्जेक्ट और इसे पास करके MapiMessage.fromMailMessage विधि। यदि EML फ़ाइल में एंबेडेड EML फ़ाइलें हैं, तो उपयोग करें MapiConversionOptions.setPreserveEmbeddedMessageFormat एंबेडेड EML फ़ाइलों का स्वरूप बनाए रखने के लिए। नीचे कोड स्निपेट दर्शाता है कि EML फ़ाइलों को कैसे लोड किया जाए MapiMessage एंबेडेड EML फ़ाइलों के स्वरूप को संरक्षित रखते हुए।
Try it out!
ईमेल और संदेश संग्रह को ऑनलाइन मुफ्त में परिवर्तित करें Aspose.Email कन्वर्ज़न ऐप.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
String dataDir = RunExamples.getDataDir_Email();
MailMessage eml = MailMessage.load(dataDir + "sample.eml", new EmlLoadOptions());
MapiConversionOptions options = MapiConversionOptions.getUnicodeFormat();
//Preserve Embedded Message Format
options.setPreserveEmbeddedMessageFormat(true);
//Convert EML to MSG with Options
MapiMessage msg = MapiMessage.fromMailMessage(eml, options);