• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SMTPReply类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: writeData

import org.apache.commons.net.smtp.SMTPReply; //导入依赖的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: send

import org.apache.commons.net.smtp.SMTPReply; //导入依赖的package包/类
public SmtpResponse send(String domain, Mail mail) throws IOException {
    SMTPClient client = new SMTPClient();
    client.connect(address, port);
    try {
        int replyCode = client.getReplyCode();
        if (!SMTPReply.isPositiveCompletion(replyCode))
            return new SmtpResponse(replyCode);
            //return error("SMTP connect failed with reply code " + replyCode);

        replyCode = client.helo(domain);
        if (!SMTPReply.isPositiveCompletion(replyCode))
            return new SmtpResponse(replyCode);
            //return error("SMTP HELO failed with reply code " + replyCode);

        replyCode = client.mail(mail.getFrom());
        if (!SMTPReply.isPositiveCompletion(replyCode))
            return new SmtpResponse(replyCode);
            //return error("SMTP MAIL FROM failed with reply code " + replyCode);

        replyCode = client.rcpt(mail.getTo());
        if (!SMTPReply.isPositiveCompletion(replyCode))
            return new SmtpResponse(replyCode);
            //return error("SMTP RCTP TO failed with reply code " + replyCode);

        client.quit();

    } finally {
        client.disconnect();
    }

    return new SmtpResponse(SMTPReply.SERVICE_CLOSING_TRANSMISSION_CHANNEL);
}
 
开发者ID:chaquotay,项目名称:whiskers,代码行数:33,代码来源:SmtpHost.java


示例3: open

import org.apache.commons.net.smtp.SMTPReply; //导入依赖的package包/类
private SMTPClient open() throws EmailException {
  final AuthSMTPClient client = new AuthSMTPClient(UTF_8.name());

  if (smtpEncryption == Encryption.SSL) {
    client.enableSSL(sslVerify);
  }

  client.setConnectTimeout(connectTimeout);
  try {
    client.connect(smtpHost, smtpPort);
    int replyCode = client.getReplyCode();
    String replyString = client.getReplyString();
    if (!SMTPReply.isPositiveCompletion(replyCode)) {
      throw new EmailException(
          String.format("SMTP server rejected connection: %d: %s", replyCode, replyString));
    }
    if (!client.login()) {
      throw new EmailException("SMTP server rejected HELO/EHLO greeting: " + replyString);
    }

    if (smtpEncryption == Encryption.TLS) {
      if (!client.startTLS(smtpHost, smtpPort, sslVerify)) {
        throw new EmailException("SMTP server does not support TLS");
      }
      if (!client.login()) {
        throw new EmailException("SMTP server rejected login: " + replyString);
      }
    }

    if (smtpUser != null && !client.auth(smtpUser, smtpPass)) {
      throw new EmailException("SMTP server rejected auth: " + replyString);
    }
    return client;
  } catch (IOException | EmailException e) {
    if (client.isConnected()) {
      try {
        client.disconnect();
      } catch (IOException e2) {
        // Ignored
      }
    }
    if (e instanceof EmailException) {
      throw (EmailException) e;
    }
    throw new EmailException(e.getMessage(), e);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:48,代码来源:SmtpEmailSender.java


示例4: testNoRecepientSpecified

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


示例5: noError

import org.apache.commons.net.smtp.SMTPReply; //导入依赖的package包/类
public static Matcher<SmtpResponse> noError() {
    return new ReplyCodeMatcher(SMTPReply.SERVICE_CLOSING_TRANSMISSION_CHANNEL);
}
 
开发者ID:chaquotay,项目名称:whiskers,代码行数:4,代码来源:SMTP.java


示例6: sendAnyMail

import org.apache.commons.net.smtp.SMTPReply; //导入依赖的package包/类
public String sendAnyMail(String target,String messagebody) throws Exception {
	loadSettings();
	message = null;
	if (smtpserver.length() < 1) {
		message = "No SMTP server defined.  Email to " + target + " was not sent.";
		logger.warn(message);
		return message;
	}
	try {
		setDefaultPort(smtpport);	// Still need to enable authentication here.
		int reply;
		logger.debug("Connecting to " + smtpserver + " on port " + smtpport + " via methodology " + smtpauth + ".  Use TLS is " + smtptls + " ...");
		connect(smtpserver);
		logger.debug(getReplyString());
		if (smtptls.equalsIgnoreCase("Yes")) {
			logger.debug("Attempting to do a STARTTLS...");
			execTLS();
			logger.debug(getReplyString());
		} else {
			logger.debug("Skipping STARTTLS attempt due to mail settings configuration.");
		}

		logger.debug("Saying EHLO....");
		ehlo("arisia.org");
		logger.debug(getReplyString());
		if (! smtpauth.equals("NONE")) {
			logger.debug("Authenticating using methodology " + smtpauth);
			AuthenticatingSMTPClient.AUTH_METHOD m = AuthenticatingSMTPClient.AUTH_METHOD.valueOf(smtpauth);
			if (auth(m, smtpusername, smtppassword)) {
				logger.debug("Authentication successful!");
			} else {
				message = "SMTP Authentication to " + smtpserver + " using " + smtpauth + " failed.  Cannot proceed.  Message is " + getReplyString();
				logger.error(message);
				throw new IOException(message);
			}
		}
		reply = getReplyCode();
		if(!SMTPReply.isPositiveCompletion(reply)) {
			message = "SMTP server " + smtpserver + " refused connection : " + reply ;
			logger.error(message);
		} else {
			logger.debug("SMTP server ready: " + reply);
			logger.debug("Sending main message...");
			if (sendSimpleMessage(smtpfromaddress,target,messagebody)) {
				logger.info("Email sent to " + target + " via " + smtpserver + " successfully.");
			} else {
				reply = getReplyCode();
				message = "Message send to " + target + " failed.  Server responded: " + reply + " (" + getReplyString() + ")";
				logger.error(message);
			}
			if (smtpbcc.length() > 1) {
				logger.info("Sending BCC copy...");
				if (sendSimpleMessage(smtpfromaddress,smtpbcc,messagebody)) {
					logger.info("Email sent to " + smtpbcc + " via " + smtpserver + " successfully.");
				} else {
					reply = getReplyCode();
					message = "Message send to " + smtpbcc + " via " + smtpserver + " failed.  Server responded: " + reply + " (" + getReplyString() + ")" ;
					logger.error(message);
				}
			}	
		}
		disconnect();
	} catch(IOException e) {
		if(isConnected()) {
			try {
				logger.debug("Forcing disconnect due to IOException");
				disconnect();
			} catch(IOException f) {
				// do nothing
			}
		}
		message = "Could not connect to server '" + smtpserver + "' : " + e.getMessage();
		logger.error(message);
	}
	return message;
}
 
开发者ID:shevett,项目名称:congo,代码行数:77,代码来源:SMTP.java


示例7: sendFriendRequest

import org.apache.commons.net.smtp.SMTPReply; //导入依赖的package包/类
public void sendFriendRequest(Convention c, Registrant r, String target,String fromWhom) throws Exception {
	loadSettings();
	Template t = templateDAO.get(cid,"Link-1");
	String templateBody = new String();
	if (t == null) {
		throw new Exception("No such template 'Link-1' found for event " + cid);
	}
	String templateSource = t.getBody();
	
	// Ready to go!
	Velocity.init();
	VelocityContext context = new VelocityContext();

	// Registrant fields...
	context.put("RegistrantEmail",target);
	context.put("RegistrantFirstName",r.getFirstName());
	context.put("RegistrantLastName",r.getLastName());
	context.put("RegistrantBadgeName",r.getBadgeName());
	context.put("RegistrantID",r.getRid());
	
	// Event fields..
	context.put("EventName",c.getConName());
	context.put("EventEmail",c.getConEmail());
	context.put("EventWebsite",c.getConWebsite());
	
	/* Generate the output */
	StringWriter out =  new StringWriter();

	Velocity.evaluate(context,out,"onthefly",templateSource);
	
	// Dump the resulting template render into what's being returned.
	templateBody = out.toString();
	logger.debug("Message, post-processing, resolves to:");
	logger.debug("---------");
	logger.debug(templateBody);
	logger.debug("---------");
	try {
		setDefaultPort(smtpport);
		int reply;
		logger.debug("Connecting to " + smtpserver + " on port " + smtpport + "...");
		connect(smtpserver);
		logger.info(getReplyString());
		reply = getReplyCode();
		if(!SMTPReply.isPositiveCompletion(reply)) {
			logger.error("SMTP server refused connection : " + reply);
		} else {
			logger.info("SMTP server ready: " + reply);
			if (sendSimpleMessage(smtpfromaddress,target,templateBody)) {
				logger.info("Message sent to " + target + " successfully.");
			} else {
				reply = getReplyCode();
				logger.error("Message send to " + target + " failed.  Server responded: " + reply);
			}
		}
		disconnect();
	} catch(IOException e) {
		if(isConnected()) {
			try {
				logger.debug("Forcing disconnect due to IOException");
				disconnect();
			} catch(IOException f) {
				// do nothing
			}
		}
		message = "Could not connect to server : '" + smtpserver + "' : " + e.getMessage();
		logger.error(message);
	}
}
 
开发者ID:shevett,项目名称:congo,代码行数:69,代码来源:SMTP.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ForgeDummyContainer类代码示例发布时间:2022-05-23
下一篇:
Java RotateEvent类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap