use of javax.mail.Transport in project zm-mailbox by Zimbra.
the class SmtpTransportTest method quitNoResponse.
@Test(timeout = 3000)
public void quitNoResponse() throws Exception {
server = MockTcpServer.scenario().sendLine("220 test ready").recvLine().sendLine("250 OK").recvLine().sendLine("250 OK").recvLine().sendLine("250 OK").recvLine().sendLine("354 OK").swallowUntil("\r\n.\r\n").sendLine("250 OK").recvLine().build().start(PORT);
Session session = JMSession.getSession();
Transport transport = session.getTransport("smtp");
transport.connect("localhost", PORT, null, null);
String raw = "From: sender@zimbra.com\nTo: rcpt@zimbra.com\nSubject: test\n\ntest";
MimeMessage msg = new ZMimeMessage(session, new SharedByteArrayInputStream(raw.getBytes(Charsets.ISO_8859_1)));
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
server.shutdown(1000);
Assert.assertEquals("EHLO localhost\r\n", server.replay());
Assert.assertEquals("MAIL FROM:<sender@zimbra.com>\r\n", server.replay());
Assert.assertEquals("RCPT TO:<rcpt@zimbra.com>\r\n", server.replay());
Assert.assertEquals("DATA\r\n", server.replay());
Assert.assertEquals("QUIT\r\n", server.replay());
Assert.assertNull(server.replay());
}
use of javax.mail.Transport in project zm-mailbox by Zimbra.
the class SmtpTransportTest method noAuthMechansims.
@Test(timeout = 3000)
public void noAuthMechansims() throws Exception {
server = MockTcpServer.scenario().sendLine("220 test ready").recvLine().sendLine("250-OK").sendLine("250 AUTH NTLM").build().start(PORT);
Session session = JMSession.getSession();
Transport transport = session.getTransport("smtp");
try {
transport.connect("localhost", PORT, "zimbra", "secret");
Assert.fail();
} catch (MessagingException e) {
Assert.assertEquals("No auth mechanism supported: [NTLM]", e.getMessage());
}
server.shutdown(1000);
}
use of javax.mail.Transport in project zm-mailbox by Zimbra.
the class SmtpTransportTest method noAuth.
@Test(timeout = 3000)
public void noAuth() throws Exception {
server = MockTcpServer.scenario().sendLine("220 test ready").recvLine().sendLine("250 OK").build().start(PORT);
Session session = JMSession.getSession();
Transport transport = session.getTransport("smtp");
try {
transport.connect("localhost", PORT, "zimbra", "secret");
Assert.fail();
} catch (MessagingException e) {
Assert.assertEquals("The server doesn't support SMTP-AUTH.", e.getMessage());
}
server.shutdown(1000);
}
use of javax.mail.Transport in project zm-mailbox by Zimbra.
the class DataSourceManager method test.
/*
* Tests connecting to a data source. Do not actually create the
* data source.
*/
public static void test(DataSource ds) throws ServiceException {
ZimbraLog.datasource.info("Testing: %s", ds);
try {
DataImport di = getInstance().getDataImport(ds, true);
di.test();
if (ds.isSmtpEnabled()) {
Session session = JMSession.getSession(ds);
Transport smtp = session.getTransport();
String emailAddress = ds.getEmailAddress();
if (smtp instanceof SmtpTransport) {
test((SmtpTransport) smtp, emailAddress);
} else {
test((SMTPTransport) smtp, emailAddress);
}
}
ZimbraLog.datasource.info("Test succeeded: %s", ds);
} catch (ServiceException x) {
ZimbraLog.datasource.info("Test failed: %s", ds, x);
throw x;
} catch (Exception e) {
ZimbraLog.datasource.info("Test failed: %s", ds, e);
throw ServiceException.INVALID_REQUEST("Datasource test failed", e);
}
}
use of javax.mail.Transport in project zm-mailbox by Zimbra.
the class MailSender method sendMessageToHost.
private void sendMessageToHost(String hostname, MimeMessage mm, Address[] rcptAddresses) throws MessagingException {
mSession.getProperties().setProperty("mail.smtp.host", hostname);
if (mEnvelopeFrom != null) {
mSession.getProperties().setProperty("mail.smtp.from", mEnvelopeFrom);
}
ZimbraLog.smtp.debug("Sending message %s to SMTP host %s with properties: %s", mm.getMessageID(), hostname, mSession.getProperties());
Transport transport = mSession.getTransport("smtp");
try {
transport.connect();
transport.sendMessage(mm, rcptAddresses);
} finally {
transport.close();
}
}
Aggregations