⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smtpservertest.java

📁 java mail,java mailjava mailjava mailjava mail
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        // this should give a 501 code cause the helo could not resolved        assertEquals("expected error: helo could not resolved", 501, smtpProtocol1.getReplyCode());                    smtpProtocol1.sendCommand("helo", helo2);        // helo is resolvable. so this should give a 250 code        assertEquals("Helo accepted", 250, smtpProtocol1.getReplyCode());        smtpProtocol1.quit();    }        public void testHeloResolvDefault() throws Exception {        finishSetUp(m_testConfiguration);        SMTPClient smtpProtocol1 = new SMTPClient();        smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);                smtpProtocol1.helo("abgsfe3rsf.de");        // helo should not be checked. so this should give a 250 code        assertEquals("Helo accepted", 250, smtpProtocol1.getReplyCode());        smtpProtocol1.quit();    }        public void testSenderDomainResolv() throws Exception {        m_testConfiguration.setSenderDomainResolv();        m_testConfiguration.setAuthorizedAddresses("192.168.0.1/32");        finishSetUp(m_testConfiguration);        SMTPClient smtpProtocol1 = new SMTPClient();        smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);                assertTrue("first connection taken", smtpProtocol1.isConnected());        // no message there, yet        assertNull("no mail received by mail server", m_mailServer.getLastMail());        smtpProtocol1.helo(InetAddress.getLocalHost().toString());        String sender1 = "mail_sender1@xfwrqqfgfe.de";        String sender2 = "mail_sender2@james.apache.org";                smtpProtocol1.setSender(sender1);        assertEquals("expected 501 error", 501, smtpProtocol1.getReplyCode());            smtpProtocol1.setSender(sender2);        smtpProtocol1.quit();            }     public void testSenderDomainResolvDefault() throws Exception {        finishSetUp(m_testConfiguration);        SMTPClient smtpProtocol1 = new SMTPClient();        smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);                smtpProtocol1.helo(InetAddress.getLocalHost().toString());                String sender1 = "mail_sender1@xfwrqqfgfe.de";                smtpProtocol1.setSender(sender1);        smtpProtocol1.quit();    }        public void testSenderDomainResolvRelayClientDefault() throws Exception {        m_testConfiguration.setSenderDomainResolv();        finishSetUp(m_testConfiguration);        SMTPClient smtpProtocol1 = new SMTPClient();        smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);                assertTrue("first connection taken", smtpProtocol1.isConnected());        // no message there, yet        assertNull("no mail received by mail server", m_mailServer.getLastMail());        smtpProtocol1.helo(InetAddress.getLocalHost().toString());        String sender1 = "mail_sender1@xfwrqqfgfe.de";                // Both mail shold        smtpProtocol1.setSender(sender1);        smtpProtocol1.quit();            }        public void testSenderDomainResolvRelayClient() throws Exception {        m_testConfiguration.setSenderDomainResolv();        m_testConfiguration.setCheckAuthClients(true);        finishSetUp(m_testConfiguration);        SMTPClient smtpProtocol1 = new SMTPClient();        smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);                assertTrue("first connection taken", smtpProtocol1.isConnected());        // no message there, yet        assertNull("no mail received by mail server", m_mailServer.getLastMail());        smtpProtocol1.helo(InetAddress.getLocalHost().toString());        String sender1 = "mail_sender1@xfwrqqfgfe.de";        String sender2 = "mail_sender2@james.apache.org";                smtpProtocol1.setSender(sender1);        assertEquals("expected 501 error", 501, smtpProtocol1.getReplyCode());            smtpProtocol1.setSender(sender2);        smtpProtocol1.quit();            }        public void testMaxRcpt() throws Exception {        m_testConfiguration.setMaxRcpt(1);        finishSetUp(m_testConfiguration);        SMTPClient smtpProtocol1 = new SMTPClient();        smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);        assertTrue("first connection taken", smtpProtocol1.isConnected());        // no message there, yet        assertNull("no mail received by mail server", m_mailServer.getLastMail());        smtpProtocol1.helo(InetAddress.getLocalHost().toString());        String sender1 = "mail_sender1@james.apache.org";        String rcpt1 = "test@localhost";        String rcpt2 = "test2@localhost";            smtpProtocol1.setSender(sender1);        smtpProtocol1.addRecipient(rcpt1);        smtpProtocol1.addRecipient(rcpt2);        assertEquals("expected 452 error", 452, smtpProtocol1.getReplyCode());                smtpProtocol1.sendShortMessageData("Subject: test\r\n\r\nTest body\r\n");                // After the data is send the rcpt count is set back to 0.. So a new mail with rcpt should be accepted                smtpProtocol1.setSender(sender1);         smtpProtocol1.addRecipient(rcpt1);                smtpProtocol1.sendShortMessageData("Subject: test\r\n\r\nTest body\r\n");                smtpProtocol1.quit();            }    public void testMaxRcptDefault() throws Exception {        finishSetUp(m_testConfiguration);        SMTPClient smtpProtocol1 = new SMTPClient();        smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);                smtpProtocol1.helo(InetAddress.getLocalHost().toString());                String sender1 = "mail_sender1@james.apache.org";        String rcpt1 = "test@localhost";                smtpProtocol1.setSender(sender1);                smtpProtocol1.addRecipient(rcpt1);                smtpProtocol1.sendShortMessageData("Subject: test\r\n\r\nTest body\r\n");                smtpProtocol1.quit();    }      public void testEhloResolv() throws Exception {        m_testConfiguration.setEhloResolv();        m_testConfiguration.setAuthorizedAddresses("192.168.0.1");        finishSetUp(m_testConfiguration);        SMTPClient smtpProtocol1 = new SMTPClient();        smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);        assertTrue("first connection taken", smtpProtocol1.isConnected());        // no message there, yet        assertNull("no mail received by mail server", m_mailServer.getLastMail());        String ehlo1 = "abgsfe3rsf.de";        String ehlo2 = "james.apache.org";                smtpProtocol1.sendCommand("ehlo", ehlo1);        // this should give a 501 code cause the ehlo could not resolved        assertEquals("expected error: ehlo could not resolved", 501, smtpProtocol1.getReplyCode());                    smtpProtocol1.sendCommand("ehlo", ehlo2);        // ehlo is resolvable. so this should give a 250 code        assertEquals("ehlo accepted", 250, smtpProtocol1.getReplyCode());        smtpProtocol1.quit();    }        public void testEhloResolvDefault() throws Exception {        finishSetUp(m_testConfiguration);        SMTPClient smtpProtocol1 = new SMTPClient();        smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);                smtpProtocol1.sendCommand("ehlo","abgsfe3rsf.de");        // ehlo should not be checked. so this should give a 250 code        assertEquals("ehlo accepted", 250, smtpProtocol1.getReplyCode());        smtpProtocol1.quit();    }        public void testEhloResolvIgnoreClientDisabled() throws Exception {        m_testConfiguration.setEhloResolv();        m_testConfiguration.setCheckAuthNetworks(true);        finishSetUp(m_testConfiguration);        SMTPClient smtpProtocol1 = new SMTPClient();        smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);        assertTrue("first connection taken", smtpProtocol1.isConnected());        // no message there, yet        assertNull("no mail received by mail server", m_mailServer.getLastMail());        String ehlo1 = "abgsfe3rsf.de";        String ehlo2 = "james.apache.org";                smtpProtocol1.sendCommand("ehlo", ehlo1);        // this should give a 501 code cause the ehlo could not resolved        assertEquals("expected error: ehlo could not resolved", 501, smtpProtocol1.getReplyCode());                    smtpProtocol1.sendCommand("ehlo", ehlo2);        // ehlo is resolvable. so this should give a 250 code        assertEquals("ehlo accepted", 250, smtpProtocol1.getReplyCode());        smtpProtocol1.quit();    }        public void testHeloEnforcement() throws Exception {        finishSetUp(m_testConfiguration);        SMTPClient smtpProtocol1 = new SMTPClient();        smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);        assertTrue("first connection taken", smtpProtocol1.isConnected());        // no message there, yet        assertNull("no mail received by mail server", m_mailServer.getLastMail());        String sender1 = "mail_sender1@localhost";        smtpProtocol1.setSender(sender1);        assertEquals("expected 503 error", 503, smtpProtocol1.getReplyCode());                smtpProtocol1.helo(InetAddress.getLocalHost().toString());                smtpProtocol1.setSender(sender1);                smtpProtocol1.quit();    }        public void testHeloEnforcementDisabled() throws Exception {        m_testConfiguration.setHeloEhloEnforcement(false);        finishSetUp(m_testConfiguration);        SMTPClient smtpProtocol1 = new SMTPClient();        smtpProtocol1.connect("127.0.0.1", m_smtpListenerPort);        assertTrue("first connection taken", smtpProtocol1.isConnected());        // no message there, yet        assertNull("no mail received by mail server", m_mailServer.getLastMail());        String sender1 = "mail_sender1@localhost";                smtpProtocol1.setSender(sender1);                smtpProtocol1.quit();    }    public void testAuth() throws Exception {        m_testConfiguration.setAuthorizedAddresses("128.0.0.1/8");        m_testConfiguration.setAuthorizingAnnounce();        finishSetUp(m_testConfiguration);        SMTPClient smtpProtocol = new SMTPClient();        smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);        smtpProtocol.sendCommand("ehlo", InetAddress.getLocalHost().toString());        String[] capabilityRes = smtpProtocol.getReplyStrings();                List capabilitieslist = new ArrayList();        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 noexistUserName = "noexist_test_user_smtp";        String sender ="test_user_smtp@localhost";        smtpProtocol.sendCommand("AUTH FOO", null);        assertEquals("expected error: unrecognized authentication type", 504, smtpProtocol.getReplyCode());        smtpProtocol.setSender(sender);        smtpProtocol.addRecipient("mail@sample.com");        assertEquals("expected 530 error", 530, smtpProtocol.getReplyCode());        assertFalse("user not existing", m_usersRepository.contains(noexistUserName));        smtpProtocol.sendCommand("AUTH PLAIN");        smtpProtocol.sendCommand(Base64.encodeAsString("\0"+noexistUserName+"\0pwd\0"));//        smtpProtocol.sendCommand(noexistUserName+"pwd".toCharArray());        assertEquals("expected error", 535, smtpProtocol.getReplyCode());        m_usersRepository.addUser(userName, "pwd");        smtpProtocol.sendCommand("AUTH PLAIN");        smtpProtocol.sendCommand(Base64.encodeAsString("\0"+userName+"\0wrongpwd\0"));        assertEquals("expected error", 535, smtpProtocol.getReplyCode());        smtpProtocol.sendCommand("AUTH PLAIN");        smtpProtocol.sendCommand(Base64.encodeAsString("\0"+userName+"\0pwd\0"));        assertEquals("authenticated", 235, smtpProtocol.getReplyCode());        smtpProtocol.sendCommand("AUTH PLAIN");        assertEquals("expected error: User has previously authenticated.", 503, smtpProtocol.getReplyCode());        smtpProtocol.addRecipient("mail@sample.com");        smtpProtocol.sendShortMessageData("Subject: test\r\n\r\nTest body\r\n");        smtpProtocol.quit();        // mail was propagated by SMTPServer        assertNotNull("mail received by mail server", m_mailServer.getLastMail());    }    public void testAuthWithEmptySender() throws Exception {        m_testConfiguration.setAuthorizedAddresses("128.0.0.1/8");        m_testConfiguration.setAuthorizingAnnounce();        finishSetUp(m_testConfiguration);        SMTPClient smtpProtocol = new SMTPClient();        smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);        smtpProtocol.sendCommand("ehlo "+InetAddress.getLocalHost());

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -