Aspose.Email में संदेश से एम्बेडेड ईमेल अटैचमेंट पढ़ें
Contents
[
Hide
]
Aspose.Email - संदेश से एम्बेडेड ईमेल अटैचमेंट पढ़ें
कभी‑कभी हमें ऐसे ईमेल मिलते हैं जिनमें अन्य ईमेल अटैचमेंट के रूप में एम्बेडेड होते हैं। ये एम्बेडेड ईमेल पूर्ण संदेश होते हैं जिनकी अपनी प्राप्तकर्ता सूची, विषय, बॉडी और यहाँ तक कि अटैचमेंट भी होते हैं। इन प्रत्येक संदेशों में भी एम्बेडेड संदेश हो सकते हैं। Aspose.Email Java का उपयोग करके डेवलपर्स प्रत्येक एम्बेडेड संदेश को व्यक्तिगत संदेश के रूप में एक्सेस कर सकते हैं। यह उदाहरण पुनरावर्ती कार्यक्षमता के उपयोग को दर्शाता है।
Java
MailMessage message = MailMessage.load(dataDir + \"embedded.msg\", MessageFormat.getMsg());
for (int i = 0; i < message.getAttachments().size(); i++)
{
Attachment att = (Attachment) message.getAttachments().get_Item(i);
System.out.println("Attachment Name: " + att.getName());
// Get the name of attachment. If msg subject contains characters like :, /, \ etc., replace with space
// because windows cannot save files with these characters
// also save first 50 characters as file name to avoid long file names
String attFileName = att.getName().replace(".eml", "").replace(":", " ").replace("\\", " ").replace("/", " ").replace("?", "");
if (attFileName.length() > 50)
{
attFileName = attFileName.substring(0, 50);
}
String attExt = (att.getName().substring(att.getName().lastIndexOf("."), att.getName().lastIndexOf(".") + 4));
// Save the attachment to disk
att.save(dataPath + attFileName + attExt);
// Check if it is an orphaned text attachment file (ATT00001.txt....) and of type eml
if ((attExt.equals(".eml")) || (att.getContentType().getMediaType().equals("text/plain") && att.getName().contains(".txt") == true && att.getName().contains("ATT") == true))
{
// Try to load this text file in MailMessage
MailMessage attMsg = MailMessage.load(dataPath + attFileName + attExt, MessageFormat.getEml());
// Call the function recursively to parse this message and attachments
ParseMessage(attMsg);
}
}चल रहा कोड डाउनलोड करें
नमूना कोड डाउनलोड करें
अधिक विवरण के लिए देखें संदेश से एम्बेडेड ईमेल अटैचमेंट पढ़ें.