com.sun.mail.smtp.SMTPAddressFailedException Java Examples

The following examples show how to use com.sun.mail.smtp.SMTPAddressFailedException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EnhancedMessagingException.java    From james-project with Apache License 2.0 6 votes vote down vote up
private Optional<Integer> computeReturnCode() {
    if (messagingException instanceof SMTPAddressFailedException) {
        SMTPAddressFailedException addressFailedException = (SMTPAddressFailedException) this.messagingException;
        return Optional.of(addressFailedException.getReturnCode());
    }
    if (messagingException instanceof SMTPSendFailedException) {
        SMTPSendFailedException sendFailedException = (SMTPSendFailedException) this.messagingException;
        return Optional.of(sendFailedException.getReturnCode());
    }
    if (messagingException instanceof SMTPSenderFailedException) {
        SMTPSenderFailedException senderFailedException = (SMTPSenderFailedException) this.messagingException;
        return Optional.of(senderFailedException.getReturnCode());
    }
    if (messagingException.getClass().getName().endsWith(".SMTPSendFailedException")
        || messagingException.getClass().getName().endsWith(".SMTPAddressSucceededException")) {
        try {
            return Optional.of((Integer)invokeGetter(messagingException, "getReturnCode"));
        } catch (ClassCastException | IllegalArgumentException | IllegalStateException e) {
            logger.error("unexpected exception", e);
        }
    }
    return Optional.empty();
}
 
Example #2
Source File: Emailer.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected boolean isNeedToRetry(Exception e) {
    if (e instanceof MailSendException) {
        if (e.getCause() instanceof SMTPAddressFailedException) {
            return false;
        }
    } else if (e instanceof AddressException) {
        return false;
    }
    return true;
}
 
Example #3
Source File: TSSmsServiceImpl.java    From jeecg with Apache License 2.0 4 votes vote down vote up
/**
 *  消息发送接口实现
 */
@Override
@Transactional
public void send() {
	LogUtil.info("===============消息发扫描开始=================");
	//List<TSSmsEntity> smsSendList = findHql("from TSSmsEntity e where e.esStatus = ? or e.esStatus = ? ", Constants.SMS_SEND_STATUS_1,Constants.SMS_SEND_STATUS_3);
	List<TSSmsEntity> smsSendList = findHql("from TSSmsEntity e where e.esStatus = ?", Constants.SMS_SEND_STATUS_1);
	if(smsSendList==null || smsSendList.size()==0){
		return;
	}
	PropertiesUtil util = new PropertiesUtil("sysConfig.properties");
	for (TSSmsEntity tsSmsEntity : smsSendList) {
		String remark = "";
		if(Constants.SMS_SEND_TYPE_2.equals(tsSmsEntity.getEsType())){
			//邮件
			try {
				MailUtil.sendEmail(util.readProperty("mail.smtpHost"), tsSmsEntity.getEsReceiver(),tsSmsEntity.getEsTitle(), 
						tsSmsEntity.getEsContent(), util.readProperty("mail.sender"), 
						util.readProperty("mail.user"), util.readProperty("mail.pwd"));
				tsSmsEntity.setEsStatus(Constants.SMS_SEND_STATUS_2);
				tsSmsEntity.setEsSendtime(new Date());
				remark = "发送成功";
				tsSmsEntity.setRemark(remark);
				updateEntitie(tsSmsEntity);
			} catch (Exception e) {
				//tsSmsEntity.setEsStatus(Constants.SMS_SEND_STATUS_3);
				if (e instanceof AuthenticationFailedException){
					remark = "认证失败错误的用户名或者密码";
				}else if (e instanceof SMTPAddressFailedException){
					remark = "接受邮箱格式不对";
				}else if (e instanceof ConnectException){
					remark = "邮件服务器连接失败";
				}else{
					remark = e.getMessage();
				}
				//System.out.println(remark);
				//e.printStackTrace();
				tsSmsEntity.setEsStatus(Constants.SMS_SEND_STATUS_3);
				tsSmsEntity.setEsSendtime(new Date());
				tsSmsEntity.setRemark(remark);
				updateEntitie(tsSmsEntity);
			}
		}
		if(Constants.SMS_SEND_TYPE_1.equals(tsSmsEntity.getEsType())){
			//短信
			String r = CMPPSenderUtil.sendMsg(tsSmsEntity.getEsReceiver(), tsSmsEntity.getEsContent());
			if ("0".equals(r)){
				tsSmsEntity.setEsStatus(Constants.SMS_SEND_STATUS_2);
			}else {
				tsSmsEntity.setEsStatus(Constants.SMS_SEND_STATUS_3);
			}
		}
		//更新发送状态
		tsSmsEntity.setRemark(remark);
		tsSmsEntity.setEsSendtime(new Date());
		updateEntitie(tsSmsEntity);
	}
	LogUtil.info("===============消息发扫描结束=================");
}