public static void deliverMail ( String [ ] recipients , String sender , String subject , MimeMessage message ) throws IOException { checkCreateSession ( ) ; try { message . setFrom ( new InternetAddress ( sender ) ) ; for ( String recipient : recipients ) { message . addRecipient ( Message . RecipientType . TO , new InternetAddress ( recipient ) ) ; } if ( subject != null ) { message . setSubject ( subject ) ; } message . saveChanges ( ) ; Address [ ] recips = message . getAllRecipients ( ) ; if ( recips == null || recips . length == 0 ) { log . info ( "Not sending mail to zero recipients" , "subject" , subject , "message" , message ) ; return ; } Transport t = _defaultSession . getTransport ( recips [ 0 ] ) ; try { t . addTransportListener ( _listener ) ; t . connect ( ) ; t . sendMessage ( message , recips ) ; } finally { t . close ( ) ; } } catch ( Exception e ) { String errmsg = "Failure sending mail [from=" + sender + ", to=" + StringUtil . toString ( recipients ) + ", subject=" + subject + "]" ; IOException ioe = new IOException ( errmsg ) ; ioe . initCause ( e ) ; throw ioe ; } }
Delivers an already - formed message to the specified recipients . This message can be any mime type including multipart .