use of com.zimbra.common.lmtp.LmtpClient 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();
}
}
}
}
use of com.zimbra.common.lmtp.LmtpClient in project zm-mailbox by Zimbra.
the class TestUtil method addMessageLmtp.
public static boolean addMessageLmtp(String[] recipients, String sender, String message) throws Exception {
String[] recipWithDomain = new String[recipients.length];
for (int i = 0; i < recipients.length; i++) {
recipWithDomain[i] = addDomainIfNecessary(recipients[i]);
}
Provisioning prov = Provisioning.getInstance();
LmtpClient lmtp = new LmtpClient("localhost", prov.getLocalServer().getIntAttr(Provisioning.A_zimbraLmtpBindPort, 7025));
byte[] data = message.getBytes();
String senderAddress = "";
if (!StringUtil.isNullOrEmpty(sender)) {
senderAddress = addDomainIfNecessary(sender);
}
boolean success = lmtp.sendMessage(new ByteArrayInputStream(data), recipWithDomain, senderAddress, "TestUtil", (long) data.length);
lmtp.close();
return success;
}
use of com.zimbra.common.lmtp.LmtpClient in project zm-mailbox by Zimbra.
the class TestLmtp method testLhloNotSendByClient.
@Test
public void testLhloNotSendByClient() throws Exception {
String[] commands = new String[] { NOOP, RSET, VRFY + " " + USER_NAME, "MAIL FROM:<" + TestUtil.addDomainIfNecessary(USER_NAME) + ">" };
LmtpClient lmtpClient;
Provisioning prov = Provisioning.getInstance();
boolean replyOk;
boolean lhloRequired = prov.getLocalServer().getBooleanAttr(Provisioning.A_zimbraLmtpLHLORequired, true);
for (String command : commands) {
lmtpClient = new LmtpClient("localhost", Provisioning.getInstance().getLocalServer().getIntAttr(Provisioning.A_zimbraLmtpBindPort, 7025));
Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
lmtpClient.sendLine(command);
replyOk = lmtpClient.replyOk();
Assert.assertTrue("Response :" + lmtpClient.getResponse() + " for command :" + command, lhloRequired ? !replyOk : replyOk);
lmtpClient.abruptClose();
}
}
use of com.zimbra.common.lmtp.LmtpClient in project zm-mailbox by Zimbra.
the class TestLmtp method testErrorWhenNoStartTlsOnSslEnforcedByServer.
@Test
public void testErrorWhenNoStartTlsOnSslEnforcedByServer() throws Exception {
boolean tlsEnforcedByServer = LC.zimbra_require_interprocess_security.booleanValue();
if (tlsEnforcedByServer) {
LmtpClient lmtpClient = new LmtpClient("localhost", Provisioning.getInstance().getLocalServer().getIntAttr(Provisioning.A_zimbraLmtpBindPort, 7025));
Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
lmtpClient.sendLine("LHLO " + LC.zimbra_server_hostname.value());
Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
if (lmtpClient.getResponse().contains("STARTTLS")) {
lmtpClient.sendLine("MAIL FROM:<" + TestUtil.addDomainIfNecessary(USER_NAME) + ">");
Assert.assertTrue(lmtpClient.getResponse(), !lmtpClient.replyOk());
}
lmtpClient.abruptClose();
}
}
use of com.zimbra.common.lmtp.LmtpClient in project zm-mailbox by Zimbra.
the class TestLmtp method testStartTLSSuccess.
@Test
public void testStartTLSSuccess() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
LmtpClient lmtpClient = new LmtpClient("localhost", Provisioning.getInstance().getLocalServer().getIntAttr(Provisioning.A_zimbraLmtpBindPort, 7025));
Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
lmtpClient.sendLine("LHLO " + LC.zimbra_server_hostname.value());
Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
if (lmtpClient.getResponse().contains(STARTTLS)) {
lmtpClient.startTLS();
lmtpClient.sendLine("LHLO " + LC.zimbra_server_hostname.value());
Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
}
lmtpClient.sendLine("MAIL FROM:<" + TestUtil.addDomainIfNecessary(USER_NAME) + ">");
Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
lmtpClient.sendLine("RCPT TO:<" + TestUtil.addDomainIfNecessary(USER_NAME) + ">");
Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
lmtpClient.sendLine("DATA");
Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
String subject = NAME_PREFIX + " testFinalDotNotSent";
lmtpClient.sendLine("Subject: " + subject);
lmtpClient.abruptClose();
// wait for some time
Thread.sleep(1000);
List<ZMessage> msgs = TestUtil.search(mbox, "in:inbox " + subject);
Assert.assertTrue("msg got delivered via LMTP even though <CRLF>.<CRLF> was not received", msgs.isEmpty());
}
Aggregations