JavaMailSenderImpl considers empty username and password as not set (for use with placeholders)
Also includes varargs declaration for applicable send methods. Issue: SPR-12294
This commit is contained in:
parent
b6a3808a97
commit
cc02269c9f
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<MimeMessage> mimeMessages = new ArrayList<MimeMessage>(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<MimeMessage> mimeMessages = new ArrayList<MimeMessage>(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<Object, Exception> failedMessages = new LinkedHashMap<Object, Exception>();
|
||||
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<Object, Exception> failedMessages = new LinkedHashMap<Object, Exception>();
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue