GroupDocs.Metadata for Java provides functionality that allows handling the most popular email message formats: EML and MSG. The following are some commonly used scenarios of working with the message content and metadata.
Reading EML message metadata
The EML message format is used by many email clients including Novell GroupWise, Microsoft Outlook Express, Lotus notes, Windows Mail, Mozilla Thunderbird, and Postbox. The files contain the email contents as plain text in MIME format, containing the email header and body, including attachments in one or more of several formats. The code sample below demonstrates how to extract metadata from an EML message.
MSG files are usually created by the Microsoft Outlook email client. The MSG format is used to represent individual email messages, appointments, contacts, tasks, and so on in the file system. The following code snippet shows how to read most common properties of an email message stored as an MSG file.
Both root package classes representing metadata in email messages (EmlRootPackage and MsgRootPackage) have the common ancestor which is the EmailRootPackage class. Since the MSG and EML formats have really similar functionality, in most cases, you don’t need to know the exact type of a loaded message. It is possible to refer to the EmailRootPackage class to access all basic features related to email messages. The following code sample shows how to remove all email message attachments using an instance of the EmailRootPackage class.
GroupDocs.Metadata for Java also allows the user to update some common email fields. The code sample below demonstrates how to alter the email subject and recipients.
try(Metadatametadata=newMetadata(Constants.InputEml)){EmailRootPackageroot=metadata.getRootPackageGeneric();root.getEmailPackage().setRecipients(newString[]{"sample@aspose.com"});root.getEmailPackage().setCarbonCopyRecipients(newString[]{"sample@groupdocs.com"});root.getEmailPackage().setSubject("RE: test subject");metadata.save(Constants.OutputEml);}
More resources
GitHub examples
You may easily run the code above and see the feature in action in our GitHub examples: