SmtpEmailSender: Open Writer in try-with-resource

Change-Id: I7f4195c9ec6b798aa3e455a01e3443a7b9b7c000
This commit is contained in:
David Pursehouse 2018-04-17 12:17:54 +02:00
parent 54c5385eca
commit d7d7d0ec41

View File

@ -200,30 +200,31 @@ public class SmtpEmailSender implements EmailSender {
}
}
Writer messageDataWriter = client.sendMessageData();
if (messageDataWriter == null) {
/* Include rejected recipient error messages here to not lose that
* information. That piece of the puzzle is vital if zero recipients
* are accepted and the server consequently rejects the DATA command.
*/
throw new EmailException(
rejected
+ "Server "
+ smtpHost
+ " rejected DATA command: "
+ client.getReplyString());
}
try (Writer messageDataWriter = client.sendMessageData()) {
if (messageDataWriter == null) {
/* Include rejected recipient error messages here to not lose that
* information. That piece of the puzzle is vital if zero recipients
* are accepted and the server consequently rejects the DATA command.
*/
throw new EmailException(
rejected
+ "Server "
+ smtpHost
+ " rejected DATA command: "
+ client.getReplyString());
}
render(messageDataWriter, callerHeaders, textBody, htmlBody);
render(messageDataWriter, callerHeaders, textBody, htmlBody);
if (!client.completePendingCommand()) {
throw new EmailException(
"Server " + smtpHost + " rejected message body: " + client.getReplyString());
}
if (!client.completePendingCommand()) {
throw new EmailException(
"Server " + smtpHost + " rejected message body: " + client.getReplyString());
}
client.logout();
if (rejected.length() > 0) {
throw new EmailException(rejected.toString());
client.logout();
if (rejected.length() > 0) {
throw new EmailException(rejected.toString());
}
}
} finally {
client.disconnect();