本文整理汇总了Java中org.apache.commons.net.smtp.SMTPClient.quit方法的典型用法代码示例。如果您正苦于以下问题:Java SMTPClient.quit方法的具体用法?Java SMTPClient.quit怎么用?Java SMTPClient.quit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.net.smtp.SMTPClient
的用法示例。
在下文中一共展示了SMTPClient.quit方法的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();
}
示例2: 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();
}
示例3: testConnectionLimit
import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
public void testConnectionLimit() throws Exception {
m_testConfiguration.setConnectionLimit(2);
finishSetUp(m_testConfiguration);
SMTPClient smtpProtocol = new SMTPClient();
smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
SMTPClient smtpProtocol2 = new SMTPClient();
smtpProtocol2.connect("127.0.0.1", m_smtpListenerPort);
SMTPClient smtpProtocol3 = new SMTPClient();
try {
smtpProtocol3.connect("127.0.0.1", m_smtpListenerPort);
Thread.sleep(3000);
fail("Shold disconnect connection 3");
} catch (Exception e) {
}
smtpProtocol.quit();
smtpProtocol.disconnect();
smtpProtocol2.quit();
smtpProtocol2.disconnect();
smtpProtocol3.connect("127.0.0.1", m_smtpListenerPort);
Thread.sleep(3000);
}
示例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());
}
示例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();
}
示例6: testTwoMailsInSequence
import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
public void testTwoMailsInSequence() 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", queue.getLastMail());
smtpProtocol1.helo(InetAddress.getLocalHost().toString());
String sender1 = "[email protected]";
String recipient1 = "[email protected]";
smtpProtocol1.setSender(sender1);
smtpProtocol1.addRecipient(recipient1);
smtpProtocol1.sendShortMessageData("Subject: test\r\n\r\nTest body testTwoMailsInSequence1\r\n");
verifyLastMail(sender1, recipient1, null);
String sender2 = "[email protected]";
String recipient2 = "[email protected]";
smtpProtocol1.setSender(sender2);
smtpProtocol1.addRecipient(recipient2);
smtpProtocol1.sendShortMessageData("Subject: test2\r\n\r\nTest body2 testTwoMailsInSequence2\r\n");
verifyLastMail(sender2, recipient2, null);
smtpProtocol1.quit();
smtpProtocol1.disconnect();
}
示例7: testHeloResolvDefault
import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
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();
}
示例8: testNoRecepientSpecified
import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
public void testNoRecepientSpecified() throws Exception {
finishSetUp(m_testConfiguration);
SMTPClient smtpProtocol = new SMTPClient();
smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
smtpProtocol.sendCommand("ehlo " + InetAddress.getLocalHost());
smtpProtocol.setSender("[email protected]");
// left out for test smtpProtocol.rcpt(new Address("[email protected]"));
smtpProtocol.sendShortMessageData("Subject: test\r\n\r\nTest body testNoRecepientSpecified\r\n");
assertTrue("sending succeeded without recepient", SMTPReply.isNegativePermanent(smtpProtocol.getReplyCode()));
smtpProtocol.quit();
// mail was propagated by SMTPServer
assertNull("no mail received by mail server", queue.getLastMail());
}
示例9: 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();
}
示例10: 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);
}
}
示例11: testSenderDomainResolv
import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
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", queue.getLastMail());
smtpProtocol1.helo(InetAddress.getLocalHost().toString());
String sender1 = "[email protected]";
smtpProtocol1.setSender(sender1);
assertEquals("expected 501 error", 501, smtpProtocol1.getReplyCode());
smtpProtocol1.addRecipient("[email protected]");
assertEquals("Recipient not accepted cause no valid sender", 503, smtpProtocol1.getReplyCode());
smtpProtocol1.quit();
}
示例12: testSenderDomainResolvRelayClient
import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
public void testSenderDomainResolvRelayClient() throws Exception {
m_testConfiguration.setSenderDomainResolv();
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", queue.getLastMail());
smtpProtocol1.helo(InetAddress.getLocalHost().toString());
String sender1 = "[email protected]";
String sender2 = "[email protected]";
smtpProtocol1.setSender(sender1);
assertEquals("expected 501 error", 501, smtpProtocol1.getReplyCode());
smtpProtocol1.setSender(sender2);
smtpProtocol1.quit();
}
示例13: 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());
}
示例14: testDNSRBLRejectWorks
import org.apache.commons.net.smtp.SMTPClient; //导入方法依赖的package包/类
public void testDNSRBLRejectWorks() throws Exception {
m_testConfiguration.setAuthorizedAddresses("192.168.0.1/32");
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 sender = "[email protected]";
smtpProtocol.setSender(sender);
smtpProtocol.addRecipient("[email protected]");
assertEquals("reject", 550, 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());
}
示例15: 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);
}
}