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


Java SMTPReply.isPositiveCompletion方法代码示例

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


在下文中一共展示了SMTPReply.isPositiveCompletion方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例5: 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.isPositiveCompletion方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。