use of com.zimbra.common.lmtp.LmtpProtocolException in project zm-mailbox by Zimbra.
the class ZimbraLmtpBackend method deliverMessageToRemoteMailboxes.
private void deliverMessageToRemoteMailboxes(Blob blob, byte[] data, LmtpEnvelope env) {
Multimap<String, LmtpAddress> serverToRecipientsMap = env.getRemoteServerToRecipientsMap();
for (String server : serverToRecipientsMap.keySet()) {
LmtpClient lmtpClient = null;
InputStream in = null;
Collection<LmtpAddress> serverRecipients = serverToRecipientsMap.get(server);
try {
Server serverObj = Provisioning.getInstance().getServerByName(server);
lmtpClient = new LmtpClient(server, new Integer(serverObj.getAttr(Provisioning.A_zimbraLmtpBindPort)));
in = data == null ? blob.getInputStream() : new ByteArrayInputStream(data);
boolean success = lmtpClient.sendMessage(in, getRecipientsEmailAddress(serverRecipients), env.getSender().getEmailAddress(), blob.getFile().getName(), blob.getRawSize());
if (success) {
setDeliveryStatuses(serverRecipients, LmtpReply.DELIVERY_OK);
} else {
ZimbraLog.lmtp.warn("Unsuccessful remote mail delivery - LMTP response: %s", lmtpClient.getResponse());
setDeliveryStatuses(serverRecipients, LmtpReply.TEMPORARY_FAILURE);
}
} catch (LmtpProtocolException e) {
ZimbraLog.lmtp.warn("Unsuccessful remote mail delivery - LMTP response: %s", e.getMessage());
setDeliveryStatuses(serverRecipients, LmtpReply.TEMPORARY_FAILURE);
} catch (Exception e) {
ZimbraLog.lmtp.warn("Exception delivering remote mail", e);
setDeliveryStatuses(serverRecipients, LmtpReply.TEMPORARY_FAILURE);
} finally {
ByteUtil.closeStream(in);
if (lmtpClient != null) {
lmtpClient.close();
}
}
}
}
Aggregations