MSG dosyasını Yükleme, Görüntüleme ve Ayrıştırma

Bu konu, bir Microsoft Outlook Mesaj dosyasını (*.msg) nasıl yükleyeceğinizi açıklar. ___ MapiMessage sınıf, MSG dosyalarını yüklemek için kullanılır ve farklı senaryolar için çeşitli statik yükleme işlevleri sunar. Aşağıdaki kod parçacığı, MSG dosyalarını bir dosyadan ya da bir akıştan nasıl yükleyeceğinizi gösterir.

MSG Dosyalarını Yükleme

Aşağıdaki kod parçacığı, MSG dosyalarını nasıl yükleyeceğinizi gösterir.

// 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());
}

Aşağıdaki kod örneği, MailMessage kullanarak MSG formatındaki bir mesajı nasıl yükleyeceğinizi gösterir.

MailMessage eml = MailMessage.load("message.msg");

Sonuçta oluşan mesajın, gömülü mesaj eklerini de içerecek şekilde EML formatına dönüştürüldüğüne dikkat edilmelidir. Orijinal mesajın bazı belirli msg format özelliklerini korumak istiyorsanız bu yükleme yöntemini kullanmayın.

Gömülü mesaj eklerinin orijinal formatını korumak için şunu kullanın: MsgLoadOptions.PreserveEmbeddedMessageFormat özellik.

MsgLoadOptions msgLoadOptions = new MsgLoadOptions();
msgLoadOptions.setPreserveEmbeddedMessageFormat(true);
MailMessage msg = MailMessage.load(stream, msgLoadOptions);

Akıştan Yükleme

Aşağıdaki kod parçacığı, bir dosyayı akıştan nasıl yükleyeceğinizi gösterir.

// 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());

}

Gömülü EML Formatını Korumakla EML’yi MSG’ye Dönüştürme

EML dosyaları ___ içine yüklenebilir MapiMessage sınıfı, bir ___ örnekleyerek MailMessage nesnesini oluşturup ___‘a geçirerek MapiMessage.fromMailMessage metodu. EML dosyası gömülü EML dosyaları içeriyorsa, şunu kullanın: MapiConversionOptions.setPreserveEmbeddedMessageFormat gömülü EML dosyalarının formatını korumak için. Aşağıdaki kod parçacığı, EML dosyalarını ___ içine yüklemeyi gösterir. MapiMessage gömülü EML dosyalarının formatını korurken.

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