*/
public void transmit(Mail mail, InetAddress inetAddress)
throws SendException, RecipientsWereRejectedException,
PostponeException {
this.mail = mail;
SmartClient smartClient = null;
try {
outgoingConnectionsRegistry.openConnection(inetAddress);
} catch (PostponeException e) {
e.setRemoteMta(remoteMta);
throw e;
}
try {
smartClient = clientFactory.create(inetAddress);
smartClient.from(mail.from.getSmtpText());
List<RecipientRejection> recipientRejections =
new ArrayList<RecipientRejection>();
List<Recipient> acceptedRecipients = new ArrayList<Recipient>();
for (Recipient recipient : mail.recipients) {
try {
smartClient.to(recipient.sourceRouteStripped());
acceptedRecipients.add(recipient);
} catch (SMTPException e) {
RemoteMtaErrorResponseException sendException =
new RemoteMtaErrorResponseException(e, remoteMta);
recipientRejections.add(new RecipientRejection(recipient,
sendException));
String logId = logIdFactory.next();
sendException.initLogId(logId);
logger.debug("Recipient " + recipient
+ " was rejected/failed. Log-ID=" + logId
+ ". Continuing with the next recipient if one "
+ "exists. " + e.getResponse());
}
}
if (acceptedRecipients.isEmpty()) {
logger.debug("All recipients were rejected");
throw new RecipientsWereRejectedException(recipientRejections);
}
smartClient.dataStart();
writeDataTo(smartClient);
smartClient.dataEnd();
if (!recipientRejections.isEmpty())
throw new RecipientsWereRejectedException(recipientRejections);
else
return;
} catch (SMTPException e) {
throw new RemoteMtaErrorResponseException(e, remoteMta);
} catch (UnknownHostException e) {
// impossible
throw new RuntimeException(e);
} catch (IOException e) {
throw new SendException("Connection failed: " + e.toString(), e,
new EnhancedStatus(450, "4.4.0",
"No answer from host or bad connection"), remoteMta);
} finally {
if (smartClient != null) {
smartClient.quit();
}
outgoingConnectionsRegistry.releaseConnection(inetAddress);
}
}