Aspose.Email for Java
Java API to Create & Send Outlook Emails
A Powerful Email Processing API that allows to create, manipulate, analyze, convert and transmit Email messages without using Microsoft Outlook.
Aspose.Email for Java is a very useful Outlook email messages generation and manipulation library that enables Java developers to work with email file formats inside their own Java applications; Which means, developers can easily access and manipulate email messages stored in formats such as MSG, PST, OST, OFT, EML, EMLX, MBOX, and VCF. This makes Aspose.Email an ideal solution for migrating email data from one format to another or for working with emails stored in archives.
Aspose.Email for Java makes it easy to create a new message from scratch and modify the existing message and update contents like subject, sender, recipients, body, attachments, etc. with just a couple of lines of Java code. Another great feature of the library is the ability to handle email attachments. With this library, developers can easily add, modify, or extract attachments from email messages. This makes it possible to work with emails and attachments in a variety of ways, including storing attachments in a database or extracting attachments for processing.
Aspose.Email for Java has included several important features for handling Outlook MSG files, such as creating new MSG documents from scratch, opening and editing existing MSG, accessing MSG contents, Parse attachments from the MSG document & saving attachments to the disk, and so on. The library also supports loading as well as reading PST files and converting it to MSG format with ease. The library also supports creating, modifying, and deleting appointments and tasks, as well as accessing information such as start and end dates, subject, and body text. The library provides detailed documentation and examples, making it easy for developers to understand how to use the library and how to integrate it into their projects.
Getting Started with Aspose.Email for Java
The recommend way to install Aspose.Email for Java is via Maven repository. You can easily use Aspose.PDF for Java API directly in your Maven Projects with simple configurations.
Maven repository for Aspose.Pdf for Java
//First, you need to specify the Aspose Maven Repository configuration/location in your Maven pom.xml as follows:
<repositories>
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://releases.aspose.com/java/repo/</url>
</repository>
</repositories>
// For a successful installation of Aspose.Email for Java, First, you need to specify the Aspose Maven Repository configuration/location in your Maven pom.xml as follows:
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-email</artifactId>
<version>22.12</version>
<classifier>jdk16</classifier>
</dependency>
</dependencies>
You can download the library directly from Aspose.Email product page
Email Messages Creation via Java API
Aspose.Email for Java makes it easy for software developers to programmatically create email messages and send it to multiple recipients inside their own Java applications. The library supports adding attachments, and setting the subject, body, sender, and recipient details with ease. You can also specify message date, message priority, message sensitivity and option for delivery notifications. It is also possible to customize email headers, create a signature for the end of the email, and create as well as send a batch of similar email messages using the mail merge feature. With just a little effort you can extract email message contents as well as email headers.
Create New Email Message & Set Properties via Java API
MailMessage message = new MailMessage();
message.setFrom(new MailAddress("sender@gmail.com"));
message.getTo().add("receiver@gmail.com");
message.setSubject("Using MailMessage Features");
// Specify message date
message.setDate(new Date());
// Specify message priority
message.setPriority(MailPriority.High);
// Specify message sensitivity
message.setSensitivity(MailSensitivity.Normal);
// Specify options for delivery notifications
message.setDeliveryNotificationOptions(DeliveryNotificationOptions.OnSuccess);
Outlook Email Message Conversion inside Java Apps
Aspose.Email for Java has included very powerful support for converting Outlook email messages to various formats with ease. The library allows conversion of Outlook email messages to HTML, MHTML, ICS, VCF, TXT, EML, MSG, and more. The MailMessage class is used to load the Outlook message file, and the save method is used to save the message in the desired format with just a few lines of code. The library also supports for detecting file formats, load & save EML messages, saving as EML preserving TNEF attachments, preserving embedded message format, EML to MSG conversion, save MSG with preserved dates, saving MailMessage as MHTML, Rendering Calendar Events, saving Message as Outlook template (.oft) file and many more.
Email Message Conversion to HTML via Java API
MailMessage msg = MailMessage.load(dataDir + "Message.msg");
msg.save(dataDir + "SavingMessageAsHTML_out1.html", SaveOptions.getDefaultHtml());
//or
MailMessage eml = MailMessage.load(dataDir + "test.eml");
HtmlSaveOptions options = SaveOptions.getDefaultHtml();
options.setEmbedResources(false);
options.setHtmlFormatOptions(HtmlFormatOptions.WriteHeader | HtmlFormatOptions.WriteCompleteEmailAddress);
eml.save(dataDir + "SavingMessageAsHTML_out2.html", options);
How to Manage Outlook Storage Files via Java API?
Aspose.Email for Java has provided several functions for working with Outlook Storage Files using Java commands. The library can be used to create a new Outlook PST file and add a subfolder to it with just a couple of lines of code. Another great feature of the library is that developers can read and convert Outlook OST files to PST and vice versa. It is also possible to read to PST file and get information about folders and subfolders. There are several other important features part of the library, such as handling messages, large PST handling, contacts, calendar items, MapiTask, MapiJournal, MapiNote and many more.
Create PST File & Add Folder to It via Java API
// Create new PST
try (PersonalStorage pst = PersonalStorage.create(path, FileFormatVersion.Unicode)) {
// Add new folder "Test"
pst.getRootFolder().addSubFolder("Inbox");
}
Work with Outlook Contacts via Java API
Aspose.Email for Java has included complete supports for working with Outlook contacts (VCards) inside Java applications. The library allows software developers to create, read, update and save contacts to disk with just a couple of lines of code. The library allows supports rendering contact information to MHTML. To achieve this you need to load VCard into MapiContact and then converted to MHTML with the help of MailMessage API.
Load VCard into MapiContact and Convert It to MHTML via Java API
String dataDir = Utils.getSharedDataDir(RenderingContactInformationToMhtml.class) + "outlook/";
//Load VCF Contact and convert to MailMessage for rendering to MHTML
MapiContact contact = MapiContact.fromVCard(dataDir + "ContactsSaqib Razzaq.vcf");
ByteArrayOutputStream os = new ByteArrayOutputStream();
contact.save(os, ContactSaveFormat.Msg);
MapiMessage msg = MapiMessage.fromStream(new ByteArrayInputStream(os.toByteArray()));
MailConversionOptions op = new MailConversionOptions();
MailMessage eml = msg.toMailMessage(op);
//Prepare the MHT format options
MhtSaveOptions mhtSaveOptions = new MhtSaveOptions();
mhtSaveOptions.setCheckBodyContentEncoding(true);
mhtSaveOptions.setPreserveOriginalBoundaries(true);
mhtSaveOptions.setMhtFormatOptions(MhtFormatOptions.RenderVCardInfo | MhtFormatOptions.WriteHeader);
mhtSaveOptions.setRenderedContactFields(ContactFieldsSet.NameInfo | ContactFieldsSet.PersonalInfo | ContactFieldsSet.Telephones | ContactFieldsSet.Events);
eml.save(dataDir + "ContactsSaqib Razzaq_out.mhtml", mhtSaveOptions);
System.out.println("Execution Completed.");