Load Email document with options
Leave feedback
This documentation describes how to load email documents with configurable options using GroupDocs.Conversion for Java. It provides developers with the ability to process and convert email files (such as MSG, EML, and MBOX) into a variety of formats, including PDF, DOCX, HTML, and more.
The EmailLoadOptions class allows customization of loading options, such as selecting specific email headers, managing attachments, and defining output parameters. These features enable precise control over email content rendering and conversion, making it a powerful tool for integrating email document handling capabilities into Java applications. The following options could be set:
Option | Description |
---|---|
setFormat() | Allows you to specify explicitly the type of the source email document. Available options are: Msg, Eml, Emlx, Pst, Ost, Vcf, Mht. |
setDisplayHeader() | Specifies option to display or hide the email header. |
setDisplayFromEmailAddress() | Specifies option to display or hide “from” email address. |
setDisplayEmailAddress() | Specifies option to display or hide email address. |
setDisplayToEmailAddress() | Specifies option to display or hide “to” email address. |
setDisplayCcEmailAddress() | Specifies option to display or hide “Cc” email address. |
setDisplayBccEmailAddress() | Specifies option to display or hide “Bcc” email address. |
The following code snippet shows how to convert an Email document and control the visibility of the fields:
import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
import com.groupdocs.conversion.options.load.EmailLoadOptions;
public class ConvertEmailWithAlteringFieldsVisibility {
public static void convert() {
EmailLoadOptions loadOptions = new EmailLoadOptions();
loadOptions.setDisplayHeader(false);
loadOptions.setDisplayFromEmailAddress(false);
loadOptions.setDisplayToEmailAddress(false);
loadOptions.setDisplayEmailAddress(false);
loadOptions.setDisplayCcEmailAddress(false);
loadOptions.setDisplayBccEmailAddress(false);
try(Converter converter = new Converter("sample.msg", () -> loadOptions)) {
PdfConvertOptions options = new PdfConvertOptions();
converter.convert("converted_with_fields.pdf", options);
}
}
public static void main(String[] args){
convert();
}
}
sample.msg
is sample file used in this example. Click here to download it.
converted_with_fields.pdf
is converted PDF document. Click here to download it.
The following code snippet shows how to convert an Email document and all attachments:
import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.contracts.SaveDocumentStreamForFileType;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
import com.groupdocs.conversion.options.load.EmailLoadOptions;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
public class ConvertEmailWithAttachments {
public static void convert() throws IOException {
EmailLoadOptions emailLoadOptions = new EmailLoadOptions();
emailLoadOptions.setConvertOwned(true);
emailLoadOptions.setConvertOwner(true);
emailLoadOptions.setDepth(2);
Converter converter=new Converter("embedded-attachment.eml", () ->emailLoadOptions);
final List<FileOutputStream> fileOutputStreams = new ArrayList<>();
try{
final int[] index = {1};
converter.convert((SaveDocumentStreamForFileType) t -> {
try{
String fileName = index[0] == 1 ? "converted.pdf" : "converted-attachment-"+(index[0] - 1) +".pdf";
index[0]++;
FileOutputStream fileOutputStream = new FileOutputStream(fileName);
fileOutputStreams.add(fileOutputStream);
return fileOutputStream;
} catch(java.io.FileNotFoundException e) {
throw new RuntimeException(e);
}
}, new PdfConvertOptions());
}finally{
for(OutputStream outputStream:fileOutputStreams){
outputStream.close();
}
}
}
public static void main(String[] args){
convert();
}
}
embedded-attachment.eml
is sample file used in this example. Click here to download it.
converted.pdf
is converted PDF document. Click here to download it.
converted_attachments.pdf
is converted PDF document. Click here to download it.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.