diff --git a/src/main/org/apache/tools/ant/listener/MailLogger.java b/src/main/org/apache/tools/ant/listener/MailLogger.java
index de9cda0c6..897f0000b 100644
--- a/src/main/org/apache/tools/ant/listener/MailLogger.java
+++ b/src/main/org/apache/tools/ant/listener/MailLogger.java
@@ -47,12 +47,12 @@ import org.apache.tools.mail.MailMessage;
*
* - MailLogger.mailhost [default: localhost] - Mail server to use
* - MailLogger.port [default: 25] - Default port for SMTP
- * - Maillogger.user [no default] - user name for SMTP auth
- * (requires JavaMail)
- * - Maillogger.password [no default] - password for SMTP auth
- * (requires JavaMail)
- * - Maillogger.ssl [default: false] - on or true if ssl is
- * needed (requires JavaMail)
+ * - MailLogger.user [no default] - user name for SMTP auth
+ * (requires Java or Jakarta Mail)
+ * - MailLogger.password [no default] - password for SMTP auth
+ * (requires Java or Jakarta Mail)
+ * - MailLogger.ssl [default: false] - on or true if ssl is
+ * needed (requires Java or Jakarta Mail)
* - MailLogger.from [required] - Mail "from" address
* - MailLogger.from [no default] - Mail "replyto" address(es),
* comma-separated
@@ -82,8 +82,8 @@ import org.apache.tools.mail.MailMessage;
* mail body for a successful build, default is to send the logfile
* - MailLogger.mimeType [default: text/plain] - MIME-Type of email
* - MailLogger.charset [no default] - character set of email
- * - Maillogger.starttls.enable [default: false] - on or true if
- * STARTTLS should be supported (requires JavaMail)
+ * - MailLogger.starttls.enable [default: false] - on or true if
+ * STARTTLS should be supported (requires Java or Jakarta Mail)
* - MailLogger.properties.file [no default] - Filename of
* properties file that will override other values.
*
@@ -386,15 +386,13 @@ public class MailLogger extends DefaultLogger {
private void sendMimeMail(Project project, Values values, String message) {
Mailer mailer = null;
try {
- mailer = ClasspathUtils.newInstance(
- "org.apache.tools.ant.taskdefs.email.MimeMailer",
+ mailer = ClasspathUtils.newInstance(getMailerImplementation(),
MailLogger.class.getClassLoader(), Mailer.class);
} catch (BuildException e) {
- Throwable t = e.getCause() == null ? e : e.getCause();
- log("Failed to initialise MIME mail: " + t.getMessage());
+ logBuildException("Failed to initialise MIME mail: ", e);
return;
}
- // convert the replyTo string into a vector of emailaddresses
+ // convert the replyTo string into a vector of EmailAddresses
Vector replyToList = splitEmailAddresses(values.replytoList());
mailer.setHost(values.mailhost());
mailer.setPort(values.port());
@@ -428,4 +426,37 @@ public class MailLogger extends DefaultLogger {
return Stream.of(listString.split(",")).map(EmailAddress::new)
.collect(Collectors.toCollection(Vector::new));
}
+
+ private String getMailerImplementation() {
+ //check to make sure that activation.jar
+ //and mail.jar are available - see bug 31969
+ try {
+ Class.forName("jakarta.activation.DataHandler");
+ Class.forName("jakarta.mail.internet.MimeMessage");
+
+ return "org.apache.tools.ant.taskdefs.email.JakartaMimeMailer";
+ } catch (ClassNotFoundException cnfe) {
+ logBuildException("Could not find Jakarta MIME mail: ",
+ new BuildException(cnfe));
+ }
+
+ try {
+ Class.forName("javax.activation.DataHandler");
+ Class.forName("javax.mail.internet.MimeMessage");
+
+ return "org.apache.tools.ant.taskdefs.email.MimeMailer";
+ } catch (ClassNotFoundException cnfe) {
+ logBuildException("Could not find MIME mail: ",
+ new BuildException(cnfe));
+ }
+
+ return "org.apache.tools.ant.taskdefs.email.Mailer";
+ }
+
+ private void logBuildException(String reason, BuildException e) {
+ Throwable t = e.getCause() == null ? e : e.getCause();
+ if (Project.MSG_WARN <= msgOutputLevel) {
+ log(reason + t.getMessage());
+ }
+ }
}