public static void sendMessageBody ( String to , String from , String subject , Object body , String contentType , ServerSetup serverSetup ) { try { Session smtpSession = getSession ( serverSetup ) ; MimeMessage mimeMessage = new MimeMessage ( smtpSession ) ; mimeMessage . setRecipients ( Message . RecipientType . TO , to ) ; mimeMessage . setFrom ( from ) ; mimeMessage . setSubject ( subject ) ; mimeMessage . setContent ( body , contentType ) ; sendMimeMessage ( mimeMessage ) ; } catch ( MessagingException e ) { throw new IllegalStateException ( "Can not send message" , e ) ; } }
Send the message with the given attributes and the given body using the specified SMTP settings