public MimeMessage createMimeMessage ( Session session ) throws MessagingException { if ( isEmpty ( htmlPart ) && isEmpty ( textPart ) ) { throw new IllegalArgumentException ( "Missing email content" ) ; } final MimeMessage msg = new MimeMessage ( session ) ; msg . setSubject ( subject ) ; msg . setFrom ( new InternetAddress ( from ) ) ; msg . setContent ( createMultiPart ( ) ) ; msg . setRecipients ( Message . RecipientType . TO , InternetAddress . parse ( recipients , false ) ) ; return msg ; }
Creates a MimeMessage containing given Multipart . Subject sender and content and session will be set .