List of usage examples for org.apache.commons.net.smtp SMTPClient setSender
public boolean setSender(String address) throws IOException
From source file:org.apache.james.smtpserver.SMTPServerTest.java
@Test public void testRelayingDenied() throws Exception { smtpConfiguration.setAuthorizedAddresses("128.0.0.1/8"); init(smtpConfiguration);/* w w w .j a v a2 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.addRecipient("maila@sample.com"); assertEquals("expected 550 error", 550, 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 w w w. j av a2 s . com*/ 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 ww w. j a v a2 s . com*/ 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);/*w ww . j av a2 s . 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);//from ww w . j a va 2s. c o 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()); }