Search in sources :

Example 1 with LmtpProtocolException

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();
            }
        }
    }
}
Also used : LmtpClient(com.zimbra.common.lmtp.LmtpClient) Server(com.zimbra.cs.account.Server) LmtpProtocolException(com.zimbra.common.lmtp.LmtpProtocolException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Rfc822ValidationInputStream(com.zimbra.common.mime.Rfc822ValidationInputStream) CopyInputStream(com.zimbra.common.util.CopyInputStream) BlobInputStream(com.zimbra.cs.store.BlobInputStream) InputStream(java.io.InputStream) MessagingException(javax.mail.MessagingException) LmtpProtocolException(com.zimbra.common.lmtp.LmtpProtocolException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) DeliveryServiceException(com.zimbra.common.service.DeliveryServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException)

Aggregations

LmtpClient (com.zimbra.common.lmtp.LmtpClient)1 LmtpProtocolException (com.zimbra.common.lmtp.LmtpProtocolException)1 Rfc822ValidationInputStream (com.zimbra.common.mime.Rfc822ValidationInputStream)1 DeliveryServiceException (com.zimbra.common.service.DeliveryServiceException)1 ServiceException (com.zimbra.common.service.ServiceException)1 CopyInputStream (com.zimbra.common.util.CopyInputStream)1 Server (com.zimbra.cs.account.Server)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 BlobInputStream (com.zimbra.cs.store.BlobInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MessagingException (javax.mail.MessagingException)1