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


Java SMTPClient类代码示例

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


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

示例1: writeData

import org.apache.commons.net.smtp.SMTPClient; //导入依赖的package包/类
private void writeData(SMTPClient smtpClient, InputStream messageStream) throws IOException {
	Writer smtpWriter = null;
	try {
		smtpWriter = smtpClient.sendMessageData();
		this.debug(smtpClient);
		if (smtpWriter == null) {
			throw new IOException("smtp writer fail !");
		}

		ByteArrayOutputStream bais = new ByteArrayOutputStream(); // no required close()
		IOUtils.copy(messageStream, bais);
		ByteArrayInputStream baos = new ByteArrayInputStream(bais.toByteArray()); // no required close()
		this.writeMessage(smtpWriter, baos);
		IOUtils.closeQuietly(smtpWriter); // do close() before pending

		smtpClient.completePendingCommand();
		this.debug(smtpClient);

		if (!SMTPReply.isPositiveCompletion(smtpClient.getReplyCode())) {
			throw new IOException("server refused connection ! - REPLY:" + smtpClient.getReplyString());
		}
	} finally {
		IOUtils.closeQuietly(smtpWriter);
	}
}
 
开发者ID:inter6,项目名称:smtp-sender,代码行数:26,代码来源:SmtpService.java

示例2: 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

示例3: 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

示例4: 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

示例5: processEnvelope

import org.apache.commons.net.smtp.SMTPClient; //导入依赖的package包/类
private Set<String> processEnvelope(SMTPClient smtpClient) throws IOException {
	smtpClient.setSender(this.mailFrom);
	this.debug(smtpClient);

	Set<String> failReceivers = new HashSet<>();
	for (String receiver : this.rcptTos) {
		if (!smtpClient.addRecipient(receiver)) {
			failReceivers.add(receiver);
		}
		this.debug(smtpClient);
	}
	return failReceivers;
}
 
开发者ID:inter6,项目名称:smtp-sender,代码行数:14,代码来源:SmtpService.java

示例6: debug

import org.apache.commons.net.smtp.SMTPClient; //导入依赖的package包/类
private void debug(Object object) {
	if (object instanceof SMTPClient) {
		this.log.debug(((SMTPClient) object).getReplyString());
	} else if (object instanceof char[]) {
		this.log.debug(new String((char[]) object));
	} else {
		this.log.debug(object.toString());
	}
}
 
开发者ID:inter6,项目名称:smtp-sender,代码行数:10,代码来源:SmtpService.java

示例7: 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);

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

示例8: 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

示例9: 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

示例10: testTwoSimultaneousMails

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

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

    assertTrue("first connection taken", smtpProtocol1.isConnected());
    assertTrue("second connection taken", smtpProtocol2.isConnected());

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

    smtpProtocol1.helo(InetAddress.getLocalHost().toString());
    smtpProtocol2.helo(InetAddress.getLocalHost().toString());

    String sender1 = "[email protected]";
    String recipient1 = "[email protected]";
    smtpProtocol1.setSender(sender1);
    smtpProtocol1.addRecipient(recipient1);

    String sender2 = "[email protected]";
    String recipient2 = "[email protected]";
    smtpProtocol2.setSender(sender2);
    smtpProtocol2.addRecipient(recipient2);

    smtpProtocol1.sendShortMessageData("Subject: test\r\n\r\nTest body testTwoSimultaneousMails1\r\n.\r\n");
    verifyLastMail(sender1, recipient1, null);

    smtpProtocol2.sendShortMessageData("Subject: test\r\n\r\nTest body testTwoSimultaneousMails2\r\n.\r\n");
    verifyLastMail(sender2, recipient2, null);

    smtpProtocol1.quit();
    smtpProtocol2.quit();

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

示例11: 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();
}
 
开发者ID:twachan,项目名称:James,代码行数:33,代码来源:SMTPServerTest.java

示例12: 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

示例13: 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();
}
 
开发者ID:twachan,项目名称:James,代码行数:13,代码来源:SMTPServerTest.java

示例14: 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

示例15: 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


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