Class EmailConverter

java.lang.Object
org.simplejavamail.converter.EmailConverter

public final class EmailConverter extends Object
Utility to help convert Email instances to other formats (MimeMessage, EML etc.) and vice versa.
If you use the Outlook parsing API, make sure you load the following dependency: org.simplejavamail::outlook-message-parser
  • Method Details

    • mimeMessageToEmail

      @NotNull public static @NotNull org.simplejavamail.api.email.Email mimeMessageToEmail(@NotNull @NotNull jakarta.mail.internet.MimeMessage mimeMessage)
    • mimeMessageToEmail

      @NotNull public static @NotNull org.simplejavamail.api.email.Email mimeMessageToEmail(@NotNull @NotNull jakarta.mail.internet.MimeMessage mimeMessage, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
    • mimeMessageToEmail

      @NotNull public static @NotNull org.simplejavamail.api.email.Email mimeMessageToEmail(@NotNull @NotNull jakarta.mail.internet.MimeMessage mimeMessage, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config, boolean fetchAttachmentData)
    • mimeMessageToEmailBuilder

      @NotNull public static @NotNull org.simplejavamail.api.email.EmailPopulatingBuilder mimeMessageToEmailBuilder(@NotNull @NotNull jakarta.mail.internet.MimeMessage mimeMessage)
    • mimeMessageToEmailBuilder

      @NotNull public static @NotNull org.simplejavamail.api.email.EmailPopulatingBuilder mimeMessageToEmailBuilder(@NotNull @NotNull jakarta.mail.internet.MimeMessage mimeMessage, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
    • mimeMessageToEmailBuilder

      @NotNull public static @NotNull org.simplejavamail.api.email.EmailPopulatingBuilder mimeMessageToEmailBuilder(@NotNull @NotNull jakarta.mail.internet.MimeMessage mimeMessage, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config, boolean fetchAttachmentData)
      Parameters:
      mimeMessage - The MimeMessage from which to create the Email.
      pkcs12Config - Private key store for decrypting S/MIME encrypted attachments (only needed when the message is encrypted rather than just signed).
      fetchAttachmentData - When false only the names of the attachments are retrieved but no data
    • outlookMsgToEmail

      @NotNull public static @NotNull org.simplejavamail.api.email.Email outlookMsgToEmail(@NotNull @NotNull String msgFileName)
      Parameters:
      msgFileName - The file name of an Outlook (.msg) message from which to create the Email.
    • outlookMsgToEmail

      @NotNull public static @NotNull org.simplejavamail.api.email.Email outlookMsgToEmail(@NotNull @NotNull String msgFileName, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
      Parameters:
      msgFileName - The file name of an Outlook (.msg) message from which to create the Email.
      pkcs12Config - Private key store for decrypting S/MIME encrypted attachments (only needed when the message is encrypted rather than just signed).
    • outlookMsgToEmailBuilderWithOutlookData

      @NotNull public static @NotNull org.simplejavamail.api.outlook.OutlookEmailConversionResult outlookMsgToEmailBuilderWithOutlookData(@NotNull @NotNull String msgFileName)
      Parameters:
      msgFileName - The file name of an Outlook (.msg) message from which to create the Email.
    • outlookMsgToEmailBuilderWithOutlookData

      @NotNull public static @NotNull org.simplejavamail.api.outlook.OutlookEmailConversionResult outlookMsgToEmailBuilderWithOutlookData(@NotNull @NotNull String msgFileName, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
      Converts an Outlook .msg message to an email builder while retaining Outlook-specific source data.
      Parameters:
      msgFileName - The file name of an Outlook (.msg) message from which to create the Email.
      pkcs12Config - Private key store for decrypting S/MIME encrypted attachments (only needed when the message is encrypted rather than just signed).
    • outlookMsgToEmail

      @NotNull public static @NotNull org.simplejavamail.api.email.Email outlookMsgToEmail(@NotNull @NotNull File msgFile)
      Delegates to outlookMsgToEmailBuilder(File) and then builds and returns the email.
      Parameters:
      msgFile - The content of an Outlook (.msg) message from which to create the Email.
    • outlookMsgToEmail

      @NotNull public static @NotNull org.simplejavamail.api.email.Email outlookMsgToEmail(@NotNull @NotNull File msgFile, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
      Delegates to outlookMsgToEmailBuilder(File, Pkcs12Config) and then builds and returns the email.
      Parameters:
      msgFile - The content of an Outlook (.msg) message from which to create the Email.
    • outlookMsgToEmailBuilder

      @NotNull public static @NotNull org.simplejavamail.api.email.EmailPopulatingBuilder outlookMsgToEmailBuilder(@NotNull @NotNull File msgFile)
      Parameters:
      msgFile - The content of an Outlook (.msg) message from which to create the Email.
    • outlookMsgToEmailBuilder

      @NotNull public static @NotNull org.simplejavamail.api.email.EmailPopulatingBuilder outlookMsgToEmailBuilder(@NotNull @NotNull File msgFile, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
      Parameters:
      msgFile - The content of an Outlook (.msg) message from which to create the Email.
      pkcs12Config - Private key store for decrypting S/MIME encrypted attachments (only needed when the message is encrypted rather than just signed).
    • outlookMsgToEmailBuilderWithOutlookData

      @NotNull public static @NotNull org.simplejavamail.api.outlook.OutlookEmailConversionResult outlookMsgToEmailBuilderWithOutlookData(@NotNull @NotNull File msgFile)
      Parameters:
      msgFile - The content of an Outlook (.msg) message from which to create the Email.
    • outlookMsgToEmailBuilderWithOutlookData

      @NotNull public static @NotNull org.simplejavamail.api.outlook.OutlookEmailConversionResult outlookMsgToEmailBuilderWithOutlookData(@NotNull @NotNull File msgFile, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
      Converts an Outlook .msg message to an email builder while retaining Outlook-specific source data.
      Parameters:
      msgFile - The content of an Outlook (.msg) message from which to create the Email.
      pkcs12Config - Private key store for decrypting S/MIME encrypted attachments (only needed when the message is encrypted rather than just signed).
    • outlookMsgToEmail

      @NotNull public static @NotNull org.simplejavamail.api.email.Email outlookMsgToEmail(@NotNull @NotNull InputStream msgInputStream)
    • outlookMsgToEmail

      @NotNull public static @NotNull org.simplejavamail.api.email.Email outlookMsgToEmail(@NotNull @NotNull InputStream msgInputStream, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
    • outlookMsgToEmailBuilder

      @NotNull @Deprecated public static @NotNull org.simplejavamail.api.internal.outlooksupport.model.EmailFromOutlookMessage outlookMsgToEmailBuilder(@NotNull @NotNull InputStream msgInputStream)
    • outlookMsgToEmailBuilder

      @NotNull @Deprecated public static @NotNull org.simplejavamail.api.internal.outlooksupport.model.EmailFromOutlookMessage outlookMsgToEmailBuilder(@NotNull @NotNull InputStream msgInputStream, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
      Note: the email builder wrapper by EmailFromOutlookMessage is set to ignore defaults as to stay as close as possible to the original MimeMessage. If you wish to use the result to send an email, you might want to first call EmailPopulatingBuilder.ignoringDefaults(boolean) to set the builder to use defaults again.
      Parameters:
      msgInputStream - The content of an Outlook (.msg) message from which to create the Email.
    • outlookMsgToEmailBuilderWithOutlookData

      @NotNull public static @NotNull org.simplejavamail.api.outlook.OutlookEmailConversionResult outlookMsgToEmailBuilderWithOutlookData(@NotNull @NotNull InputStream msgInputStream)
      Parameters:
      msgInputStream - The content of an Outlook (.msg) message from which to create the Email.
    • outlookMsgToEmailBuilderWithOutlookData

      @NotNull public static @NotNull org.simplejavamail.api.outlook.OutlookEmailConversionResult outlookMsgToEmailBuilderWithOutlookData(@NotNull @NotNull InputStream msgInputStream, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
      Converts an Outlook .msg message to an email builder while retaining Outlook-specific source data.
      Parameters:
      msgInputStream - The content of an Outlook (.msg) message from which to create the Email.
      pkcs12Config - Private key store for decrypting S/MIME encrypted attachments (only needed when the message is encrypted rather than just signed).
    • emlToEmail

      @NotNull public static @NotNull org.simplejavamail.api.email.Email emlToEmail(@NotNull @NotNull InputStream emlInputStream)
    • emlToEmail

      @NotNull public static @NotNull org.simplejavamail.api.email.Email emlToEmail(@NotNull @NotNull InputStream emlInputStream, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
      Delegates to emlToEmail(InputStream, Pkcs12Config, Session) using a dummy Session instance.
    • emlToEmail

      @NotNull public static @NotNull org.simplejavamail.api.email.Email emlToEmail(@NotNull @NotNull InputStream emlInputStream, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config, @NotNull @NotNull jakarta.mail.Session session)
      Delegates to emlToEmailBuilder(InputStream, Pkcs12Config) with the full string value read from the given InputStream.
    • emlToEmail

      @NotNull public static @NotNull org.simplejavamail.api.email.Email emlToEmail(@NotNull @NotNull String eml)
    • emlToEmail

      @NotNull public static @NotNull org.simplejavamail.api.email.Email emlToEmail(@NotNull @NotNull String eml, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
      Delegates to emlToEmail(String, Pkcs12Config, Session) using a dummy Session instance.
    • emlToEmail

      @NotNull public static @NotNull org.simplejavamail.api.email.Email emlToEmail(@NotNull @NotNull String eml, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config, @NotNull @NotNull jakarta.mail.Session session)
    • emlToEmail

      @NotNull public static @NotNull org.simplejavamail.api.email.Email emlToEmail(@NotNull @NotNull File emlFile)
    • emlToEmail

      @NotNull public static @NotNull org.simplejavamail.api.email.Email emlToEmail(@NotNull @NotNull File emlFile, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
      Delegates to emlToEmail(File, Pkcs12Config, Session) using a dummy Session instance.
    • emlToEmail

      @NotNull public static @NotNull org.simplejavamail.api.email.Email emlToEmail(@NotNull @NotNull File emlFile, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config, @NotNull @NotNull jakarta.mail.Session session)
    • emlToEmailBuilder

      @NotNull public static @NotNull org.simplejavamail.api.email.EmailPopulatingBuilder emlToEmailBuilder(@NotNull @NotNull File emlFile)
      Delegates to emlToEmailBuilder(File, Session) using a dummy Session instance.
    • emlToEmailBuilder

      @NotNull public static @NotNull org.simplejavamail.api.email.EmailPopulatingBuilder emlToEmailBuilder(@NotNull @NotNull File emlFile, @NotNull @NotNull jakarta.mail.Session session)
    • emlToEmailBuilder

      @NotNull public static @NotNull org.simplejavamail.api.email.EmailPopulatingBuilder emlToEmailBuilder(@NotNull @NotNull File emlFile, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
      Delegates to emlToEmailBuilder(File, Pkcs12Config, Session) using a dummy Session instance.
    • emlToEmailBuilder

      @NotNull public static @NotNull org.simplejavamail.api.email.EmailPopulatingBuilder emlToEmailBuilder(@NotNull @NotNull File emlFile, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config, @NotNull @NotNull jakarta.mail.Session session)
    • emlToEmailBuilder

      @NotNull public static @NotNull org.simplejavamail.api.email.EmailPopulatingBuilder emlToEmailBuilder(@NotNull @NotNull InputStream emlInputStream)
      Delegates to emlToEmailBuilder(InputStream, Session) using a dummy Session instance.
    • emlToEmailBuilder

      @NotNull public static @NotNull org.simplejavamail.api.email.EmailPopulatingBuilder emlToEmailBuilder(@NotNull @NotNull InputStream emlInputStream, @NotNull @NotNull jakarta.mail.Session session)
    • emlToEmailBuilder

      @NotNull public static @NotNull org.simplejavamail.api.email.EmailPopulatingBuilder emlToEmailBuilder(@NotNull @NotNull InputStream emlInputStream, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
      Delegates to emlToEmailBuilder(InputStream, Pkcs12Config, Session) using a dummy Session instance.
    • emlToEmailBuilder

      @NotNull public static @NotNull org.simplejavamail.api.email.EmailPopulatingBuilder emlToEmailBuilder(@NotNull @NotNull InputStream emlInputStream, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config, @NotNull @NotNull jakarta.mail.Session session)
      Delegates to emlToEmailBuilder(String, Pkcs12Config, Session) with the full string value read from the given InputStream.
    • emlToEmailBuilder

      @NotNull public static @NotNull org.simplejavamail.api.email.EmailPopulatingBuilder emlToEmailBuilder(@NotNull @NotNull String eml)
      Delegates to emlToEmailBuilder(String, Session) using a dummy Session instance.
    • emlToEmailBuilder

      @NotNull public static @NotNull org.simplejavamail.api.email.EmailPopulatingBuilder emlToEmailBuilder(@NotNull @NotNull String eml, @NotNull @NotNull jakarta.mail.Session session)
    • emlToEmailBuilder

      @NotNull public static @NotNull org.simplejavamail.api.email.EmailPopulatingBuilder emlToEmailBuilder(@NotNull @NotNull String eml, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
      Delegates to emlToEmailBuilder(String, Pkcs12Config, Session) using a dummy Session instance.
    • emlToEmailBuilder

      @NotNull public static @NotNull org.simplejavamail.api.email.EmailPopulatingBuilder emlToEmailBuilder(@NotNull @NotNull String eml, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config, @NotNull @NotNull jakarta.mail.Session session)
      Delegates to emlToMimeMessage(String, Session) using a dummy Session instance and passes the result to mimeMessageToEmailBuilder(MimeMessage, Pkcs12Config).
    • outlookMsgToMimeMessage

      @NotNull public static @NotNull jakarta.mail.internet.MimeMessage outlookMsgToMimeMessage(@NotNull @NotNull String msgFileName)
      Parameters:
      msgFileName - The file name of an Outlook (.msg) message to convert.
    • outlookMsgToMimeMessage

      @NotNull public static @NotNull jakarta.mail.internet.MimeMessage outlookMsgToMimeMessage(@NotNull @NotNull String msgFileName, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
      Parameters:
      msgFileName - The file name of an Outlook (.msg) message to convert.
      pkcs12Config - Private key store for decrypting S/MIME encrypted attachments (only needed when the message is encrypted rather than just signed).
      Returns:
      Result of outlookMsgToEmail(String, Pkcs12Config) and emailToMimeMessage(Email).
    • outlookMsgToMimeMessage

      @NotNull public static @NotNull jakarta.mail.internet.MimeMessage outlookMsgToMimeMessage(@NotNull @NotNull File outlookMsgFile)
    • outlookMsgToMimeMessage

      @NotNull public static @NotNull jakarta.mail.internet.MimeMessage outlookMsgToMimeMessage(@NotNull @NotNull File outlookMsgFile, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
      Returns:
      Result of outlookMsgToEmail(File, Pkcs12Config) and emailToMimeMessage(Email).
    • outlookMsgToMimeMessage

      @NotNull public static @NotNull jakarta.mail.internet.MimeMessage outlookMsgToMimeMessage(@NotNull @NotNull InputStream outlookMsgInputStream)
    • outlookMsgToMimeMessage

      @NotNull public static @NotNull jakarta.mail.internet.MimeMessage outlookMsgToMimeMessage(@NotNull @NotNull InputStream outlookMsgInputStream, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
      Returns:
      Result of outlookMsgToEmail(InputStream, Pkcs12Config) and emailToMimeMessage(Email).
    • emailToMimeMessage

      public static jakarta.mail.internet.MimeMessage emailToMimeMessage(@NotNull @NotNull org.simplejavamail.api.email.Email email)
      Delegates to emailToMimeMessage(Email, Session, EmailGovernance), using a new empty Session instance, and without email governance - but defaults from (system) prorties (files) are still applied, if provided..
    • emailToMimeMessage

      public static jakarta.mail.internet.MimeMessage emailToMimeMessage(@NotNull @NotNull org.simplejavamail.api.email.Email email, org.simplejavamail.api.mailer.config.EmailGovernance emailGovernance)
      Delegates to emailToMimeMessage(Email, Session, EmailGovernance), using a new empty Session instance.
    • emailToMimeMessage

      public static jakarta.mail.internet.MimeMessage emailToMimeMessage(@NotNull @NotNull org.simplejavamail.api.email.Email email, @NotNull @NotNull jakarta.mail.Session session)
      Delegates to emailToMimeMessage(Email, Session, EmailGovernance) with no email governance - but defaults from (system) prorties (files) are still applied, if provided.
    • emailToMimeMessage

      public static jakarta.mail.internet.MimeMessage emailToMimeMessage(@NotNull @NotNull org.simplejavamail.api.email.Email email, @NotNull @NotNull jakarta.mail.Session session, @NotNull @NotNull org.simplejavamail.api.mailer.config.EmailGovernance emailGovernance)
      Delegates to MimeMessageProducerHelper.produceMimeMessage(Email, Session).
    • emlToMimeMessage

      @NotNull public static @NotNull jakarta.mail.internet.MimeMessage emlToMimeMessage(@NotNull @NotNull File emlFile)
      Delegates to emlToMimeMessage(File, Session), using createDummySession().
    • emlToMimeMessage

      public static jakarta.mail.internet.MimeMessage emlToMimeMessage(@NotNull @NotNull File emlFile, @NotNull @NotNull jakarta.mail.Session session)
    • emlToMimeMessage

      @NotNull public static @NotNull jakarta.mail.internet.MimeMessage emlToMimeMessage(@NotNull @NotNull InputStream inputStream)
      Delegates to emlToMimeMessage(InputStream, Session) using createDummySession().
    • emlToMimeMessage

      @NotNull public static @NotNull jakarta.mail.internet.MimeMessage emlToMimeMessage(@NotNull @NotNull InputStream inputStream, @NotNull @NotNull jakarta.mail.Session session)
      Relies on JavaMail's native parser of EML data, MimeMessage(Session, InputStream).
      See Also:
      • MimeMessage(Session, InputStream)
    • emlToMimeMessage

      public static jakarta.mail.internet.MimeMessage emlToMimeMessage(@NotNull @NotNull String eml)
      Delegates to emlToMimeMessage(String, Session) with an empty Session instance.
    • emlToMimeMessage

      public static jakarta.mail.internet.MimeMessage emlToMimeMessage(@NotNull @NotNull String eml, @NotNull @NotNull jakarta.mail.Session session)
      Relies on JavaMail's native parser of EML data, MimeMessage(Session, InputStream).
    • mimeMessageToEMLByteArray

      public static byte[] mimeMessageToEMLByteArray(@NotNull @NotNull jakarta.mail.internet.MimeMessage mimeMessage)
      Returns:
      The result of MimeMessage.writeTo(OutputStream) which should be in the standard EML format.
    • mimeMessageToEML

      public static String mimeMessageToEML(@NotNull @NotNull jakarta.mail.internet.MimeMessage mimeMessage)
      Returns:
      The result of MimeMessage.writeTo(OutputStream) with which should be in the standard EML format, to UTF8 string.
    • emailToEML

      public static String emailToEML(@NotNull @NotNull org.simplejavamail.api.email.Email email)
      Delegates to emailToMimeMessage(Email) and passes the result to mimeMessageToEML(MimeMessage).
      See Also:
    • outlookMsgToEML

      @NotNull public static @NotNull String outlookMsgToEML(@NotNull @NotNull String msgFileName)
      Parameters:
      msgFileName - The file name of an Outlook (.msg) message to convert.
    • outlookMsgToEML

      @NotNull public static @NotNull String outlookMsgToEML(@NotNull @NotNull String msgFileName, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
      Parameters:
      msgFileName - The file name of an Outlook (.msg) message to convert.
      pkcs12Config - Private key store for decrypting S/MIME encrypted attachments (only needed when the message is encrypted rather than just signed).
      Returns:
      Result of outlookMsgToEmail(String, Pkcs12Config) and emailToEML(Email)
    • outlookMsgToEML

      @NotNull public static @NotNull String outlookMsgToEML(@NotNull @NotNull File outlookMsgFile)
    • outlookMsgToEML

      @NotNull public static @NotNull String outlookMsgToEML(@NotNull @NotNull File outlookMsgFile, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
      Returns:
      Result of outlookMsgToEmail(File, Pkcs12Config) and emailToEML(Email)
    • outlookMsgToEML

      @NotNull public static @NotNull String outlookMsgToEML(@NotNull @NotNull InputStream outlookMsgInputStream)
    • outlookMsgToEML

      @NotNull public static @NotNull String outlookMsgToEML(@NotNull @NotNull InputStream outlookMsgInputStream, @Nullable @Nullable org.simplejavamail.api.mailer.config.Pkcs12Config pkcs12Config)
      Returns:
      Result of outlookMsgToEmail(InputStream, Pkcs12Config) and emailToEML(Email)