List of usage examples for org.apache.commons.net.smtp SMTPClient connect
public void connect(InetAddress host, int port) throws SocketException, IOException
From source file:org.apache.james.smtpserver.SMTPServerTest.java
@Test public void testMultipleMailsAndRset() throws Exception { init(smtpConfiguration);/*from ww w . j a v a 2 s .co m*/ SMTPClient smtpProtocol = new SMTPClient(); smtpProtocol.connect("127.0.0.1", smtpListenerPort); smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost()); smtpProtocol.setSender("mail@sample.com"); smtpProtocol.reset(); smtpProtocol.setSender("mail@sample.com"); smtpProtocol.quit(); // mail was propagated by SMTPServer assertNull("no mail received by mail server", queue.getLastMail()); }
From source file:org.apache.james.smtpserver.SMTPServerTest.java
@Test public void testRelayingDenied() throws Exception { smtpConfiguration.setAuthorizedAddresses("128.0.0.1/8"); init(smtpConfiguration);/*from www . j av a2s . c o m*/ SMTPClient smtpProtocol = new SMTPClient(); smtpProtocol.connect("127.0.0.1", smtpListenerPort); smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost()); smtpProtocol.setSender("mail@sample.com"); smtpProtocol.addRecipient("maila@sample.com"); assertEquals("expected 550 error", 550, smtpProtocol.getReplyCode()); }
From source file:org.apache.james.smtpserver.SMTPServerTest.java
@Test public void testHandleAnnouncedMessageSizeLimitExceeded() throws Exception { smtpConfiguration.setMaxMessageSize(1); // set message limit to 1kb init(smtpConfiguration);//from ww w . j av a 2 s . co m SMTPClient smtpProtocol = new SMTPClient(); smtpProtocol.connect("127.0.0.1", smtpListenerPort); smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost()); smtpProtocol.sendCommand("MAIL FROM:<mail@localhost> SIZE=1025", null); assertEquals("expected error: max msg size exceeded", 552, smtpProtocol.getReplyCode()); smtpProtocol.addRecipient("mail@localhost"); assertEquals("expected error", 503, smtpProtocol.getReplyCode()); }
From source file:org.apache.james.smtpserver.SMTPServerTest.java
public void testHandleMessageSizeLimitExceeded() throws Exception { smtpConfiguration.setMaxMessageSize(1); // set message limit to 1kb init(smtpConfiguration);//from ww w.j a v a2 s. c o m SMTPClient smtpProtocol = new SMTPClient(); smtpProtocol.connect("127.0.0.1", smtpListenerPort); smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost()); smtpProtocol.setSender("mail@localhost"); smtpProtocol.addRecipient("mail@localhost"); Writer wr = smtpProtocol.sendMessageData(); // create Body with more than 1kb . 502 wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100"); wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100"); wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100"); wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100"); wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100\r\n"); // second line wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100"); wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100"); wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100"); wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100"); wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100"); wr.write("123456781012345678201\r\n"); // 521 + CRLF = 523 + 502 => 1025 wr.close(); assertFalse(smtpProtocol.completePendingCommand()); assertEquals("expected 552 error", 552, smtpProtocol.getReplyCode()); }
From source file:org.apache.james.smtpserver.SMTPServerTest.java
@Test public void testHandleMessageSizeLimitRespected() throws Exception { smtpConfiguration.setMaxMessageSize(1); // set message limit to 1kb init(smtpConfiguration);/*from w w w .j a va 2 s.co m*/ SMTPClient smtpProtocol = new SMTPClient(); smtpProtocol.connect("127.0.0.1", smtpListenerPort); smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost()); smtpProtocol.setSender("mail@localhost"); smtpProtocol.addRecipient("mail@localhost"); Writer wr = smtpProtocol.sendMessageData(); // create Body with less than 1kb wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100"); wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100"); wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100"); wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100"); wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100"); wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100"); wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100"); wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100"); wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100"); wr.write( "1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100"); wr.write("1234567810123456782012\r\n"); // 1022 + CRLF = 1024 wr.close(); assertTrue(smtpProtocol.completePendingCommand()); assertEquals("expected 250 ok", 250, smtpProtocol.getReplyCode()); }
From source file:org.apache.james.smtpserver.SMTPServerTest.java
@Test public void testDNSRBLNotRejectAuthUser() throws Exception { smtpConfiguration.setAuthorizedAddresses("192.168.0.1/32"); smtpConfiguration.setAuthorizingAnnounce(); smtpConfiguration.useRBL(true);//from w w w.j a v a 2s. co m init(smtpConfiguration); dnsServer.setLocalhostByName(InetAddress.getByName("127.0.0.1")); SMTPClient smtpProtocol = new SMTPClient(); smtpProtocol.connect("127.0.0.1", smtpListenerPort); smtpProtocol.sendCommand("ehlo", InetAddress.getLocalHost().toString()); String[] capabilityRes = smtpProtocol.getReplyStrings(); List<String> capabilitieslist = new ArrayList<String>(); for (int i = 1; i < capabilityRes.length; i++) { capabilitieslist.add(capabilityRes[i].substring(4)); } assertTrue("anouncing auth required", capabilitieslist.contains("AUTH LOGIN PLAIN")); // is this required or just for compatibility? assertTrue("anouncing // auth required", capabilitieslist.contains("AUTH=LOGIN PLAIN")); String userName = "test_user_smtp"; String sender = "test_user_smtp@localhost"; smtpProtocol.setSender(sender); usersRepository.addUser(userName, "pwd"); smtpProtocol.sendCommand("AUTH PLAIN"); smtpProtocol.sendCommand(Base64.encodeAsString("\0" + userName + "\0pwd\0")); assertEquals("authenticated", 235, smtpProtocol.getReplyCode()); smtpProtocol.addRecipient("mail@sample.com"); assertEquals("authenticated.. not reject", 250, smtpProtocol.getReplyCode()); smtpProtocol.sendShortMessageData("Subject: test\r\n\r\nTest body testDNSRBLNotRejectAuthUser\r\n"); smtpProtocol.quit(); // mail was propagated by SMTPServer assertNotNull("mail received by mail server", queue.getLastMail()); }
From source file:org.apache.james.smtpserver.SMTPServerTest.java
@Test public void testDNSRBLRejectWorks() throws Exception { smtpConfiguration.setAuthorizedAddresses("192.168.0.1/32"); smtpConfiguration.useRBL(true);// w w w . j a v a 2s . co m init(smtpConfiguration); dnsServer.setLocalhostByName(InetAddress.getByName("127.0.0.1")); SMTPClient smtpProtocol = new SMTPClient(); smtpProtocol.connect("127.0.0.1", smtpListenerPort); smtpProtocol.sendCommand("ehlo", InetAddress.getLocalHost().toString()); String sender = "test_user_smtp@localhost"; smtpProtocol.setSender(sender); smtpProtocol.addRecipient("mail@sample.com"); assertEquals("reject", 554, smtpProtocol.getReplyCode()); smtpProtocol.sendShortMessageData("Subject: test\r\n\r\nTest body testDNSRBLRejectWorks\r\n"); smtpProtocol.quit(); // mail was rejected by SMTPServer assertNull("mail reject by mail server", queue.getLastMail()); }
From source file:org.apache.james.smtpserver.SMTPServerTest.java
@Test public void testAddressBracketsEnforcementDisabled() throws Exception { smtpConfiguration.setAddressBracketsEnforcement(false); init(smtpConfiguration);// w ww . j av a2 s .c om SMTPClient smtpProtocol = new SMTPClient(); smtpProtocol.connect("127.0.0.1", smtpListenerPort); smtpProtocol.sendCommand("ehlo", InetAddress.getLocalHost().toString()); smtpProtocol.sendCommand("mail from:", "test@localhost"); assertEquals("accept", 250, smtpProtocol.getReplyCode()); smtpProtocol.sendCommand("rcpt to:", "mail@sample.com"); assertEquals("accept", 250, smtpProtocol.getReplyCode()); smtpProtocol.quit(); smtpProtocol.connect("127.0.0.1", smtpListenerPort); smtpProtocol.sendCommand("ehlo", InetAddress.getLocalHost().toString()); smtpProtocol.sendCommand("mail from:", "<test@localhost>"); assertEquals("accept", 250, smtpProtocol.getReplyCode()); smtpProtocol.sendCommand("rcpt to:", "<mail@sample.com>"); assertEquals("accept", 250, smtpProtocol.getReplyCode()); smtpProtocol.quit(); }
From source file:org.apache.james.smtpserver.SMTPServerTest.java
@Test public void testAddressBracketsEnforcementEnabled() throws Exception { init(smtpConfiguration);/* www. j ava 2 s. c o m*/ SMTPClient smtpProtocol = new SMTPClient(); smtpProtocol.connect("127.0.0.1", smtpListenerPort); smtpProtocol.sendCommand("ehlo", InetAddress.getLocalHost().toString()); smtpProtocol.sendCommand("mail from:", "test@localhost"); assertEquals("reject", 501, smtpProtocol.getReplyCode()); smtpProtocol.sendCommand("mail from:", "<test@localhost>"); assertEquals("accept", 250, smtpProtocol.getReplyCode()); smtpProtocol.sendCommand("rcpt to:", "mail@sample.com"); assertEquals("reject", 501, smtpProtocol.getReplyCode()); smtpProtocol.sendCommand("rcpt to:", "<mail@sample.com>"); assertEquals("accept", 250, smtpProtocol.getReplyCode()); smtpProtocol.quit(); }