Class MailContent


  • public class MailContent
    extends Object
    Author:
    Yohann Chastagnier
    • Method Detail

      • of

        public static MailContent of​(String content)
        Gets a new instance of MimeMessage by specifying a content as a string.
        Parameters:
        content - the string content
        Returns:
        a new instance of MimeMessage.
      • of

        public static MailContent of​(javax.mail.Multipart multipart)
        Gets a new instance of MimeMessage by specifying a content as a Multipart.
        Parameters:
        multipart - the Multipart content
        Returns:
        a new instance of MimeMessage.
      • normalizeHtmlContent

        public static String normalizeHtmlContent​(String htmlContent)
        Normalizes the given HTML content in order to be sent safely by mail infrastructure.

        If HTML TAG container does not exists, then the normalization is performed. HTML, HEAD and BODY are created and all declared styles in BODY are moved to HEAD part in order to get as most as possible compatibility email reader.

        Parameters:
        htmlContent - an HTML content.
        Returns:
        a string representing the normalized HTML content.
      • extractTextBodyPartFromHtmlContent

        public static javax.mail.internet.MimeBodyPart extractTextBodyPartFromHtmlContent​(String htmlContent)
        Gets a MimeBodyPart filled with text content extracted from given HTML content.
        Parameters:
        htmlContent - an HTML content.
        Returns:
        a MimeBodyPart.
      • getHtmlBodyPartFromHtmlContent

        public static javax.mail.internet.MimeBodyPart getHtmlBodyPartFromHtmlContent​(String htmlContent)
        Gets a MimeBodyPart initialized with given HTML content into UTF8 encoding.
        Parameters:
        htmlContent - an HTML content as UTF8 encoding.
        Returns:
        a MimeBodyPart.
      • notHtml

        public MailContent notHtml()
        Forces the information that the content is not an HTML one. By default, the content is considered as an HTML one.
        Returns:
        the instance of MailContent.
      • withContentType

        public MailContent withContentType​(String contentType)
        Sets the content type.
        Parameters:
        contentType - the content type to set.
        Returns:
        the instance of MailContent.
      • applyOn

        public void applyOn​(javax.mail.internet.MimeMessage message)
                     throws javax.mail.MessagingException
        Applies the content information on a MimeMessage. If the content is a string and contains <html> TAG, then the content is considered as an HTML one, even if isHtml() returns false.
        Parameters:
        message - the MimeMessage.
        Throws:
        javax.mail.MessagingException - if an error occurs with the message