حفظ رسالة البريد الإلكتروني كملف PDF

Aspose.Email - حفظ رسالة البريد الإلكتروني كملف PDF

يُظهر الكود التالي تحويل رسالة البريد إلى PDF باستخدام Aspose.Email بالتزامن مع Aspose.Words for Java. يتضمن ذلك الخطوات التالية:

  1. حمّل رسالة البريد باستخدام MailMessage
  2. احفظ رسالة البريد إلى MemoryStream كملف MHTML
  3. حمّل التدفق باستخدام Aspose.Words
  4. احفظ الرسالة كملف PDF

Java

FileInputStream fstream = new FileInputStream(dataDir + "message.msg");
MailMessage eml = MailMessage.load(fstream);
// Save the Message to output stream in MHTML format
ByteArrayOutputStream emlStream = new ByteArrayOutputStream();
eml.save(emlStream, SaveOptions.getDefaultMhtml());
// Load the stream into a Word document; the Aspose.Words types are qualified
// because com.aspose.email has a LoadOptions class of its own
com.aspose.words.LoadOptions lo = new com.aspose.words.LoadOptions();
lo.setLoadFormat(com.aspose.words.LoadFormat.MHTML);
com.aspose.words.Document doc = new com.aspose.words.Document(
        new ByteArrayInputStream(emlStream.toByteArray()), lo);

// Save to disk
doc.save(dataDir + "message.pdf", com.aspose.words.SaveFormat.PDF);

// or save to a stream
ByteArrayOutputStream foStream = new ByteArrayOutputStream();
doc.save(foStream, com.aspose.words.SaveFormat.PDF);

تحميل الكود القابل للتنفيذ

تحميل عينة الكود