@ -17,10 +17,15 @@
package org.springframework.mail.javamail ;
package org.springframework.mail.javamail ;
import java.io.InputStream ;
import java.io.InputStream ;
import java.util.ArrayList ;
import java.util.List ;
import javax.mail.MessagingException ;
import jakarta.mail.internet.MimeMessage ;
import jakarta.mail.internet.MimeMessage ;
import org.springframework.mail.MailException ;
import org.springframework.mail.MailException ;
import org.springframework.mail.MailParseException ;
import org.springframework.mail.MailPreparationException ;
import org.springframework.mail.MailSender ;
import org.springframework.mail.MailSender ;
/ * *
/ * *
@ -92,7 +97,9 @@ public interface JavaMailSender extends MailSender {
* in case of failure when sending the message
* in case of failure when sending the message
* @see # createMimeMessage
* @see # createMimeMessage
* /
* /
void send ( MimeMessage mimeMessage ) throws MailException ;
default void send ( MimeMessage mimeMessage ) throws MailException {
send ( new MimeMessage [ ] { mimeMessage } ) ;
}
/ * *
/ * *
* Send the given array of JavaMail MIME messages in batch .
* Send the given array of JavaMail MIME messages in batch .
@ -121,7 +128,9 @@ public interface JavaMailSender extends MailSender {
* @throws org . springframework . mail . MailSendException
* @throws org . springframework . mail . MailSendException
* in case of failure when sending the message
* in case of failure when sending the message
* /
* /
void send ( MimeMessagePreparator mimeMessagePreparator ) throws MailException ;
default void send ( MimeMessagePreparator mimeMessagePreparator ) throws MailException {
send ( new MimeMessagePreparator [ ] { mimeMessagePreparator } ) ;
}
/ * *
/ * *
* Send the JavaMail MIME messages prepared by the given MimeMessagePreparators .
* Send the JavaMail MIME messages prepared by the given MimeMessagePreparators .
@ -138,6 +147,25 @@ public interface JavaMailSender extends MailSender {
* @throws org . springframework . mail . MailSendException
* @throws org . springframework . mail . MailSendException
* in case of failure when sending a message
* in case of failure when sending a message
* /
* /
void send ( MimeMessagePreparator . . . mimeMessagePreparators ) throws MailException ;
default void send ( MimeMessagePreparator . . . mimeMessagePreparators ) throws MailException {
try {
List < MimeMessage > mimeMessages = new ArrayList < > ( mimeMessagePreparators . length ) ;
for ( MimeMessagePreparator preparator : mimeMessagePreparators ) {
MimeMessage mimeMessage = createMimeMessage ( ) ;
preparator . prepare ( mimeMessage ) ;
mimeMessages . add ( mimeMessage ) ;
}
send ( mimeMessages . toArray ( new MimeMessage [ 0 ] ) ) ;
}
catch ( MailException ex ) {
throw ex ;
}
catch ( MessagingException ex ) {
throw new MailParseException ( ex ) ;
}
catch ( Exception ex ) {
throw new MailPreparationException ( ex ) ;
}
}
}
}