diff --git a/spring-context-support/src/main/java/org/springframework/mail/MailSender.java b/spring-context-support/src/main/java/org/springframework/mail/MailSender.java index 6b87d7bb99b..bcccc6821ff 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/MailSender.java +++ b/spring-context-support/src/main/java/org/springframework/mail/MailSender.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,25 +34,19 @@ public interface MailSender { /** * Send the given simple mail message. * @param simpleMessage the message to send - * @throws org.springframework.mail.MailParseException - * in case of failure when parsing the message - * @throws org.springframework.mail.MailAuthenticationException - * in case of authentication failure - * @throws org.springframework.mail.MailSendException - * in case of failure when sending the message + * @throws MailParseException in case of failure when parsing the message + * @throws MailAuthenticationException in case of authentication failure + * @throws MailSendException in case of failure when sending the message */ void send(SimpleMailMessage simpleMessage) throws MailException; /** * Send the given array of simple mail messages in batch. * @param simpleMessages the messages to send - * @throws org.springframework.mail.MailParseException - * in case of failure when parsing a message - * @throws org.springframework.mail.MailAuthenticationException - * in case of authentication failure - * @throws org.springframework.mail.MailSendException - * in case of failure when sending a message + * @throws MailParseException in case of failure when parsing a message + * @throws MailAuthenticationException in case of authentication failure + * @throws MailSendException in case of failure when sending a message */ - void send(SimpleMailMessage[] simpleMessages) throws MailException; + void send(SimpleMailMessage... simpleMessages) throws MailException; } diff --git a/spring-context-support/src/main/java/org/springframework/mail/javamail/JavaMailSender.java b/spring-context-support/src/main/java/org/springframework/mail/javamail/JavaMailSender.java index 7372f625126..a3bf54208e0 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/javamail/JavaMailSender.java +++ b/spring-context-support/src/main/java/org/springframework/mail/javamail/JavaMailSender.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.mail.javamail; import java.io.InputStream; - import javax.mail.internet.MimeMessage; import org.springframework.mail.MailException; @@ -104,7 +103,7 @@ public interface JavaMailSender extends MailSender { * in case of failure when sending a message * @see #createMimeMessage */ - void send(MimeMessage[] mimeMessages) throws MailException; + void send(MimeMessage... mimeMessages) throws MailException; /** * Send the JavaMail MIME message prepared by the given MimeMessagePreparator. @@ -138,6 +137,6 @@ public interface JavaMailSender extends MailSender { * @throws org.springframework.mail.MailSendException * in case of failure when sending a message */ - void send(MimeMessagePreparator[] mimeMessagePreparators) throws MailException; + void send(MimeMessagePreparator... mimeMessagePreparators) throws MailException; } diff --git a/spring-context-support/src/main/java/org/springframework/mail/javamail/JavaMailSenderImpl.java b/spring-context-support/src/main/java/org/springframework/mail/javamail/JavaMailSenderImpl.java index 3993d28ee07..d7d617ab6d9 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/javamail/JavaMailSenderImpl.java +++ b/spring-context-support/src/main/java/org/springframework/mail/javamail/JavaMailSenderImpl.java @@ -16,7 +16,6 @@ package org.springframework.mail.javamail; -import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Date; @@ -294,11 +293,11 @@ public class JavaMailSenderImpl implements JavaMailSender { @Override public void send(SimpleMailMessage simpleMessage) throws MailException { - send(new SimpleMailMessage[] { simpleMessage }); + send(new SimpleMailMessage[] {simpleMessage}); } @Override - public void send(SimpleMailMessage[] simpleMessages) throws MailException { + public void send(SimpleMailMessage... simpleMessages) throws MailException { List mimeMessages = new ArrayList(simpleMessages.length); for (SimpleMailMessage simpleMessage : simpleMessages) { MimeMailMessage message = new MimeMailMessage(createMimeMessage()); @@ -342,17 +341,17 @@ public class JavaMailSenderImpl implements JavaMailSender { } @Override - public void send(MimeMessage[] mimeMessages) throws MailException { + public void send(MimeMessage... mimeMessages) throws MailException { doSend(mimeMessages, null); } @Override public void send(MimeMessagePreparator mimeMessagePreparator) throws MailException { - send(new MimeMessagePreparator[] { mimeMessagePreparator }); + send(new MimeMessagePreparator[] {mimeMessagePreparator}); } @Override - public void send(MimeMessagePreparator[] mimeMessagePreparators) throws MailException { + public void send(MimeMessagePreparator... mimeMessagePreparators) throws MailException { try { List mimeMessages = new ArrayList(mimeMessagePreparators.length); for (MimeMessagePreparator preparator : mimeMessagePreparators) { @@ -368,9 +367,6 @@ public class JavaMailSenderImpl implements JavaMailSender { catch (MessagingException ex) { throw new MailParseException(ex); } - catch (IOException ex) { - throw new MailPreparationException(ex); - } catch (Exception ex) { throw new MailPreparationException(ex); } @@ -389,12 +385,20 @@ public class JavaMailSenderImpl implements JavaMailSender { * in case of failure when sending a message */ protected void doSend(MimeMessage[] mimeMessages, Object[] originalMessages) throws MailException { - Map failedMessages = new LinkedHashMap(); + String username = getUsername(); + String password = getPassword(); + if ("".equals(username)) { // probably from a placeholder + username = null; + if ("".equals(password)) { // in conjunction with "" username, this means no password to use + password = null; + } + } + Map failedMessages = new LinkedHashMap(); Transport transport; try { transport = getTransport(getSession()); - transport.connect(getHost(), getPort(), getUsername(), getPassword()); + transport.connect(getHost(), getPort(), username, password); } catch (AuthenticationFailedException ex) { throw new MailAuthenticationException(ex);