当前位置: 首页>>代码示例>>Java>>正文


Java SMTPClient.sendCommand方法代码示例

本文整理汇总了Java中org.apache.commons.net.smtp.SMTPClient.sendCommand方法的典型用法代码示例。如果您正苦于以下问题:Java SMTPClient.sendCommand方法的具体用法?Java SMTPClient.sendCommand怎么用?Java SMTPClient.sendCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.net.smtp.SMTPClient的用法示例。


在下文中一共展示了SMTPClient.sendCommand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMaxLineLength

import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
public void testMaxLineLength() throws Exception {
    finishSetUp(m_testConfiguration);

    SMTPClient smtpProtocol = new SMTPClient();
    smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);

    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < AbstractChannelPipelineFactory.MAX_LINE_LENGTH; i++) {
        sb.append("A");
    }
    smtpProtocol.sendCommand("EHLO " + sb.toString());
    System.out.println(smtpProtocol.getReplyString());
    assertEquals("Line length exceed", 500, smtpProtocol.getReplyCode());

    smtpProtocol.sendCommand("EHLO test");
    assertEquals("Line length ok", 250, smtpProtocol.getReplyCode());

    smtpProtocol.quit();
    smtpProtocol.disconnect();
}
 
开发者ID:twachan,项目名称:James,代码行数:21,代码来源:SMTPServerTest.java

示例2: testAuthWithEmptySender

import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
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());

    String userName = "test_user_smtp";
    m_usersRepository.addUser(userName, "pwd");

    smtpProtocol.setSender("");

    smtpProtocol.sendCommand("AUTH PLAIN");
    smtpProtocol.sendCommand(Base64.encodeAsString("\0" + userName + "\0pwd\0"));
    assertEquals("authenticated", 235, smtpProtocol.getReplyCode());

    smtpProtocol.addRecipient("[email protected]");
    assertEquals("expected error", 503, smtpProtocol.getReplyCode());

    smtpProtocol.quit();
}
 
开发者ID:twachan,项目名称:James,代码行数:25,代码来源:SMTPServerTest.java

示例3: testAddressBracketsEnforcementEnabled

import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
public void testAddressBracketsEnforcementEnabled() throws Exception {
    finishSetUp(m_testConfiguration);
    SMTPClient smtpProtocol = new SMTPClient();
    smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);

    smtpProtocol.sendCommand("ehlo", InetAddress.getLocalHost().toString());

    smtpProtocol.sendCommand("mail from:", "[email protected]");
    assertEquals("reject", 501, smtpProtocol.getReplyCode());
    smtpProtocol.sendCommand("mail from:", "<[email protected]>");
    assertEquals("accept", 250, smtpProtocol.getReplyCode());

    smtpProtocol.sendCommand("rcpt to:", "[email protected]");
    assertEquals("reject", 501, smtpProtocol.getReplyCode());
    smtpProtocol.sendCommand("rcpt to:", "<[email protected]>");
    assertEquals("accept", 250, smtpProtocol.getReplyCode());

    smtpProtocol.quit();
}
 
开发者ID:twachan,项目名称:James,代码行数:20,代码来源:SMTPServerTest.java

示例4: testSimpleMailSendWithEHLO

import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
public void testSimpleMailSendWithEHLO() throws Exception {
    finishSetUp(m_testConfiguration);

    SMTPClient smtpProtocol = new SMTPClient();
    smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);

    // no message there, yet
    assertNull("no mail received by mail server", queue.getLastMail());

    smtpProtocol.sendCommand("EHLO " + InetAddress.getLocalHost());
    String[] capabilityRes = smtpProtocol.getReplyStrings();

    List<String> capabilitieslist = new ArrayList<String>();
    for (int i = 1; i < capabilityRes.length; i++) {
        capabilitieslist.add(capabilityRes[i].substring(4));
    }

    assertEquals("capabilities", 3, capabilitieslist.size());
    assertTrue("capabilities present PIPELINING", capabilitieslist.contains("PIPELINING"));
    assertTrue("capabilities present ENHANCEDSTATUSCODES", capabilitieslist.contains("ENHANCEDSTATUSCODES"));
    assertTrue("capabilities present 8BITMIME", capabilitieslist.contains("8BITMIME"));

    smtpProtocol.setSender("[email protected]");
    smtpProtocol.addRecipient("[email protected]");

    smtpProtocol.sendShortMessageData("Subject: test\r\n\r\nBody\r\n\r\n.\r\n");
    smtpProtocol.quit();
    smtpProtocol.disconnect();

    // mail was propagated by SMTPServer
    assertNotNull("mail received by mail server", queue.getLastMail());
}
 
开发者ID:twachan,项目名称:James,代码行数:33,代码来源:SMTPServerTest.java

示例5: testStartTLSInEHLO

import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
public void testStartTLSInEHLO() throws Exception {
    m_testConfiguration.setStartTLS();
    finishSetUp(m_testConfiguration);

    SMTPClient smtpProtocol = new SMTPClient();
    smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);

    // no message there, yet
    assertNull("no mail received by mail server", queue.getLastMail());

    smtpProtocol.sendCommand("EHLO " + InetAddress.getLocalHost());
    String[] capabilityRes = smtpProtocol.getReplyStrings();

    List<String> capabilitieslist = new ArrayList<String>();
    for (int i = 1; i < capabilityRes.length; i++) {
        capabilitieslist.add(capabilityRes[i].substring(4));
    }

    assertEquals("capabilities", 4, capabilitieslist.size());
    assertTrue("capabilities present PIPELINING", capabilitieslist.contains("PIPELINING"));
    assertTrue("capabilities present ENHANCEDSTATUSCODES", capabilitieslist.contains("ENHANCEDSTATUSCODES"));
    assertTrue("capabilities present 8BITMIME", capabilitieslist.contains("8BITMIME"));
    assertTrue("capabilities present STARTTLS", capabilitieslist.contains("STARTTLS"));

    smtpProtocol.quit();
    smtpProtocol.disconnect();

}
 
开发者ID:twachan,项目名称:James,代码行数:29,代码来源:SMTPServerTest.java

示例6: doTestHeloEhloResolv

import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
private void doTestHeloEhloResolv(String heloCommand) throws IOException {
    SMTPClient smtpProtocol = new SMTPClient();
    smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);

    assertTrue("first connection taken", smtpProtocol.isConnected());

    // no message there, yet
    assertNull("no mail received by mail server", queue.getLastMail());

    String fictionalDomain = "abgsfe3rsf.de";
    String existingDomain = "james.apache.org";
    String mail = "[email protected]";
    String rcpt = "[email protected]";

    smtpProtocol.sendCommand(heloCommand, fictionalDomain);
    smtpProtocol.setSender(mail);
    smtpProtocol.addRecipient(rcpt);

    // this should give a 501 code cause the helo/ehlo could not resolved
    assertEquals("expected error: " + heloCommand + " could not resolved", 501, smtpProtocol.getReplyCode());

    smtpProtocol.sendCommand(heloCommand, existingDomain);
    smtpProtocol.setSender(mail);
    smtpProtocol.addRecipient(rcpt);

    if (smtpProtocol.getReplyCode() == 501) {
        fail(existingDomain + " domain currently cannot be resolved (check your DNS/internet connection/proxy settings to make test pass)");
    }
    // helo/ehlo is resolvable. so this should give a 250 code
    assertEquals(heloCommand + " accepted", 250, smtpProtocol.getReplyCode());

    smtpProtocol.quit();
}
 
开发者ID:twachan,项目名称:James,代码行数:34,代码来源:SMTPServerTest.java

示例7: testEhloResolvDefault

import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
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();
}
 
开发者ID:twachan,项目名称:James,代码行数:13,代码来源:SMTPServerTest.java

示例8: testRelayingDenied

import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
public void testRelayingDenied() throws Exception {
    m_testConfiguration.setAuthorizedAddresses("128.0.0.1/8");
    finishSetUp(m_testConfiguration);

    SMTPClient smtpProtocol = new SMTPClient();
    smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);

    smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost());

    smtpProtocol.setSender("[email protected]");

    smtpProtocol.addRecipient("[email protected]");
    assertEquals("expected 550 error", 550, smtpProtocol.getReplyCode());
}
 
开发者ID:twachan,项目名称:James,代码行数:15,代码来源:SMTPServerTest.java

示例9: testHandleAnnouncedMessageSizeLimitExceeded

import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
public void testHandleAnnouncedMessageSizeLimitExceeded() throws Exception {
    m_testConfiguration.setMaxMessageSize(1); // set message limit to 1kb
    finishSetUp(m_testConfiguration);

    SMTPClient smtpProtocol = new SMTPClient();
    smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);

    smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost());

    smtpProtocol.sendCommand("MAIL FROM:<[email protected]> SIZE=1025", null);
    assertEquals("expected error: max msg size exceeded", 552, smtpProtocol.getReplyCode());

    smtpProtocol.addRecipient("[email protected]");
    assertEquals("expected error", 503, smtpProtocol.getReplyCode());
}
 
开发者ID:twachan,项目名称:James,代码行数:16,代码来源:SMTPServerTest.java

示例10: testHandleMessageSizeLimitExceeded

import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
public void testHandleMessageSizeLimitExceeded() throws Exception {
    m_testConfiguration.setMaxMessageSize(1); // set message limit to 1kb
    finishSetUp(m_testConfiguration);

    SMTPClient smtpProtocol = new SMTPClient();
    smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);

    smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost());

    smtpProtocol.setSender("[email protected]");
    smtpProtocol.addRecipient("[email protected]");

    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());

}
 
开发者ID:twachan,项目名称:James,代码行数:34,代码来源:SMTPServerTest.java

示例11: testHandleMessageSizeLimitRespected

import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
public void testHandleMessageSizeLimitRespected() throws Exception {
    m_testConfiguration.setMaxMessageSize(1); // set message limit to 1kb
    finishSetUp(m_testConfiguration);

    SMTPClient smtpProtocol = new SMTPClient();
    smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);

    smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost());

    smtpProtocol.setSender("[email protected]");
    smtpProtocol.addRecipient("[email protected]");

    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());

}
 
开发者ID:twachan,项目名称:James,代码行数:33,代码来源:SMTPServerTest.java

示例12: testReverseEqualsHelo

import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
public void testReverseEqualsHelo() throws Exception {
    m_testConfiguration.setReverseEqualsHelo();
    m_testConfiguration.setAuthorizedAddresses("192.168.0.1");
    // temporary alter the loopback resolution
    try {
        m_dnsServer.setLocalhostByName(InetAddress.getByName("james.apache.org"));
    } catch (UnknownHostException e) {
        fail("james.apache.org currently cannot be resolved (check your DNS/internet connection/proxy settings to make test pass)");
    }
    try {
        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", queue.getLastMail());

        String helo1 = "abgsfe3rsf.de";
        String helo2 = "james.apache.org";
        String mail = "sender";
        String rcpt = "recipient";

        smtpProtocol1.sendCommand("helo", helo1);
        smtpProtocol1.setSender(mail);
        smtpProtocol1.addRecipient(rcpt);

        // this should give a 501 code cause the helo not equal reverse of
        // ip
        assertEquals("expected error: helo not equals reverse of ip", 501, smtpProtocol1.getReplyCode());

        smtpProtocol1.sendCommand("helo", helo2);
        smtpProtocol1.setSender(mail);
        smtpProtocol1.addRecipient(rcpt);

        // helo is resolvable. so this should give a 250 code
        assertEquals("Helo accepted", 250, smtpProtocol1.getReplyCode());

        smtpProtocol1.quit();
    } finally {
        m_dnsServer.setLocalhostByName(null);
    }
}
 
开发者ID:twachan,项目名称:James,代码行数:46,代码来源:SMTPServerTest.java

示例13: testReverseEqualsEhlo

import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
public void testReverseEqualsEhlo() throws Exception {
    m_testConfiguration.setReverseEqualsEhlo();
    m_testConfiguration.setAuthorizedAddresses("192.168.0.1");
    // temporary alter the loopback resolution
    InetAddress jamesDomain = null;
    try {
        jamesDomain = m_dnsServer.getByName("james.apache.org");
    } catch (UnknownHostException e) {
        fail("james.apache.org currently cannot be resolved (check your DNS/internet connection/proxy settings to make test pass)");
    }
    m_dnsServer.setLocalhostByName(jamesDomain);
    try {
        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", queue.getLastMail());

        String ehlo1 = "abgsfe3rsf.de";
        String ehlo2 = "james.apache.org";
        String mail = "sender";
        String rcpt = "recipient";

        smtpProtocol1.sendCommand("ehlo", ehlo1);
        smtpProtocol1.setSender(mail);
        smtpProtocol1.addRecipient(rcpt);

        // this should give a 501 code cause the ehlo not equals reverse of
        // ip
        assertEquals("expected error: ehlo not equals reverse of ip", 501, smtpProtocol1.getReplyCode());

        smtpProtocol1.sendCommand("ehlo", ehlo2);
        smtpProtocol1.setSender(mail);
        smtpProtocol1.addRecipient(rcpt);

        // ehlo is resolvable. so this should give a 250 code
        assertEquals("ehlo accepted", 250, smtpProtocol1.getReplyCode());

        smtpProtocol1.quit();
    } finally {
        m_dnsServer.setLocalhostByName(null);
    }
}
 
开发者ID:twachan,项目名称:James,代码行数:48,代码来源:SMTPServerTest.java

示例14: testAuthCancel

import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
public void testAuthCancel() throws Exception {
    m_testConfiguration.setAuthorizedAddresses("127.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());

    smtpProtocol.sendCommand("AUTH PLAIN");

    assertEquals("start auth.", 334, smtpProtocol.getReplyCode());

    smtpProtocol.sendCommand("*");

    assertEquals("cancel auth.", 501, smtpProtocol.getReplyCode());

    smtpProtocol.quit();

}
 
开发者ID:twachan,项目名称:James,代码行数:22,代码来源:SMTPServerTest.java

示例15: testAuth

import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
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<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 noexistUserName = "noexist_test_user_smtp";
    String sender = "[email protected]";
    smtpProtocol.sendCommand("AUTH FOO", null);
    assertEquals("expected error: unrecognized authentication type", 504, smtpProtocol.getReplyCode());

    smtpProtocol.setSender(sender);

    smtpProtocol.addRecipient("[email protected]");
    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("[email protected]");
    smtpProtocol.sendShortMessageData("Subject: test\r\n\r\nTest body testAuth\r\n");

    smtpProtocol.quit();

    // mail was propagated by SMTPServer
    assertNotNull("mail received by mail server", queue.getLastMail());
}
 
开发者ID:twachan,项目名称:James,代码行数:61,代码来源:SMTPServerTest.java


注:本文中的org.apache.commons.net.smtp.SMTPClient.sendCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。