本文整理汇总了Java中org.apache.commons.net.smtp.SMTPClient.getReplyStrings方法的典型用法代码示例。如果您正苦于以下问题:Java SMTPClient.getReplyStrings方法的具体用法?Java SMTPClient.getReplyStrings怎么用?Java SMTPClient.getReplyStrings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.net.smtp.SMTPClient
的用法示例。
在下文中一共展示了SMTPClient.getReplyStrings方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: 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();
}
示例3: 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());
}
示例4: testDNSRBLNotRejectAuthUser
import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
public void testDNSRBLNotRejectAuthUser() throws Exception {
m_testConfiguration.setAuthorizedAddresses("192.168.0.1/32");
m_testConfiguration.setAuthorizingAnnounce();
m_testConfiguration.useRBL(true);
finishSetUp(m_testConfiguration);
m_dnsServer.setLocalhostByName(InetAddress.getByName("127.0.0.1"));
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 sender = "[email protected]";
smtpProtocol.setSender(sender);
m_usersRepository.addUser(userName, "pwd");
smtpProtocol.sendCommand("AUTH PLAIN");
smtpProtocol.sendCommand(Base64.encodeAsString("\0" + userName + "\0pwd\0"));
assertEquals("authenticated", 235, smtpProtocol.getReplyCode());
smtpProtocol.addRecipient("[email protected]");
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());
}