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


Java MailException.getMessage方法代码示例

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


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

示例1: send

import org.springframework.mail.MailException; //导入方法依赖的package包/类
@Retryable
public boolean send(ConfirmationInfo confirmationInfo) throws Exception {
    boolean atLeastOneSent = false;
    Iterator<RecipientInfo> recipientInfoIterator = confirmationInfo.getRecipientInfoIterator();
    while (recipientInfoIterator.hasNext()) {
        RecipientInfo currentRecipientInfo = recipientInfoIterator.next();
        try {
            log.info("send confirmation to: " + currentRecipientInfo);
            mailService.sendMailWithTemplate(getConfirmationEmailBuilder(confirmationInfo).getTemplateMailTO(currentRecipientInfo, confirmationInfo));
            atLeastOneSent = true;
        } catch (MailException e) {
            String message = e.getMessage();
            if (message != null && !message.isEmpty() && message.indexOf("Invalid Addresses") > 0) {
                // bypass the retry and log the invalid address - but send for the next recipient
                log.error("Invalid Addresses detected - currentRecipientInfo: " + currentRecipientInfo.getRecipientsEmail(), e);
            } else {
                // retry, if no Invalid Addresses
                throw e;
            }
        }
    }
    return atLeastOneSent;
}
 
开发者ID:huihoo,项目名称:olat,代码行数:24,代码来源:ConfirmationDelegate.java

示例2: send

import org.springframework.mail.MailException; //导入方法依赖的package包/类
/**
 * @Retryable since it could throw a MailException if the sendMailWithTemplate fails, so we might want to retry. <br/>
 *            However, if an "Invalid Addresses" is the reason for the failure, is useless to retry, <br/>
 *            so we throw a new exception (InvalidAddressException) which is not catched by the TransactionRetryer.
 */
@Retryable
public void send(Subscriber subscriber, List<NotificationEventTO> events) throws Exception {
    String emailAddress = subscriber.getIdentity().getAttributes().getEmail();
    try {
        mailService.sendMailWithTemplate(emailBuilder.getTemplateMailTO(emailAddress, events));
    } catch (MailException e) {
        String message = e.getMessage();
        if (message != null && !message.isEmpty() && message.indexOf("Invalid Addresses") > 0) {
            // bypass the retry
            log.error("Invalid Addresses detected !!! ", e);
            throw new InvalidAddressException(e, emailAddress);
        }
        throw e;
    }
}
 
开发者ID:huihoo,项目名称:olat,代码行数:21,代码来源:MailChannel.java

示例3: sendToOneRecipient

import org.springframework.mail.MailException; //导入方法依赖的package包/类
private boolean sendToOneRecipient(MailMessage messageClone, String toEmailAddress) {
    boolean delivered = false;
    try {
        LOG.info("send message to: " + toEmailAddress);
        mailService.sendMailWithAttachments(emailBuilder.getMailTemplate(toEmailAddress, messageClone));
        delivered = true;
    } catch (MailException ex) {
        String exMessage = ex.getMessage();
        if (messageClone != null && !exMessage.isEmpty() && exMessage.indexOf("Invalid Addresses") > 0) {
            delivered = false;
            // bypass the retry and log the invalid address - but send for the next recipient
            LOG.error("Invalid Addresses detected !!! " + toEmailAddress, ex);
        } else {
            // retry, if no Invalid Addresses
            throw ex;
        }
    } finally {
        notifyMetrics(delivered);
    }
    return delivered;
}
 
开发者ID:huihoo,项目名称:olat,代码行数:22,代码来源:ConfirmationServiceImpl.java

示例4: sendVelocityTemplateMailWithoutAttachment

import org.springframework.mail.MailException; //导入方法依赖的package包/类
private void sendVelocityTemplateMailWithoutAttachment(final String fromAddress, final List<String> toAddress, final List<String> ccAddress, final String subject,
                                                       final Map<String, Object> modelForMailContent, final String templateName, final boolean isTemplateHtml) throws Exception {
    MimeMessagePreparator preparator = new MimeMessagePreparator() {
        @Override
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
            helper.setSubject(subject);
            helper.setFrom(fromAddress);
            helper.setTo(toAddress.toArray(new String[toAddress.size()]));

            if (ccAddress != null && ccAddress.size() > 0) {
                helper.setCc(ccAddress.toArray(new String[ccAddress.size()]));
            }

            String text = geVelocityTemplateContent(modelForMailContent, templateName);
            log.debug("Template Name :" + templateName + "Template content : " + text);

            // use the true flag to indicate you need a multipart message
            helper.setText(text, isTemplateHtml);
        }
    };
    try {
        mailSender.send(preparator);
        log.debug("Template Mail without attachment successfully sent !! \nFrom Addres: " + fromAddress + " To Address: " + toAddress + " CC Address: " + ccAddress + "\n Subject: " + subject);
        log.debug(subject);
    } catch (MailException ex) {
        log.error("Error Sending Velocity Template mail: " + ex.getMessage());
        log.error("Sending mail failed for \nFrom Addres: " + fromAddress + " To Address: " + toAddress + " CC Address: " + ccAddress + "\n Subject: " + subject + " Template Name: " + templateName + " isTemplateHtml: " + isTemplateHtml);
        throw new Exception("Error Sending Velocity Template mail. " + ex.getMessage(), ex);
    }
}
 
开发者ID:Mahidharmullapudi,项目名称:timesheet-upload,代码行数:32,代码来源:EmailServiceImpl.java

示例5: sendMimeMailWithoutAttachment

import org.springframework.mail.MailException; //导入方法依赖的package包/类
@Override
public void sendMimeMailWithoutAttachment(final String fromAddress, final List<String> toAddress, final List<String> ccAddress, final String subject,
                                          final String mailContent, final boolean isMailHtml) throws Exception {

    MimeMessagePreparator preparator = new MimeMessagePreparator() {
        @Override
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
            helper.setSubject(subject);
            helper.setFrom(fromAddress);
            helper.setTo(toAddress.toArray(new String[toAddress.size()]));

            if (ccAddress != null && ccAddress.size() > 0) {
                helper.setCc(ccAddress.toArray(new String[ccAddress.size()]));
            }

            // use the true flag to indicate you need a multipart message
            helper.setText(mailContent, isMailHtml);
        }
    };
    try {
        mailSender.send(preparator);
        log.debug("EMail without attachment successfully sent !! \nFrom Addres: " + fromAddress + " To Address: " + toAddress + " CC Address: " + ccAddress + "\n Subject: " + subject);
        log.debug(subject);
    } catch (MailException ex) {
        log.error("Error Sending email: " + ex.getMessage());
        log.error("Sending mail failed for \nFrom Addres: " + fromAddress + " To Address: " + toAddress + " CC Address: " + ccAddress + "\n Subject: " + subject + " Content: " + mailContent + " isTemplateHtml: " + isMailHtml);
        throw new Exception("Error Sending Velocity Template mail. " + ex.getMessage(), ex);
    }

}
 
开发者ID:Mahidharmullapudi,项目名称:timesheet-upload,代码行数:32,代码来源:EmailServiceImpl.java

示例6: send

import org.springframework.mail.MailException; //导入方法依赖的package包/类
/**
 * @Retryable since it could throw a MailException if the sendMailWithTemplate fails, so we might want to retry. <br/>
 *            However, if an "Invalid Addresses" is the reason for the failure, is useless to retry, <br/>
 *            so we throw a new exception (InvalidAddressException) which is not catched by the TransactionRetryer.
 */
@Retryable
public void send(Subscriber subscriber, List<NotificationEventTO> events) throws Exception {
    try {
        mailService.sendMailWithTemplate(emailBuilder.getTemplateMailTO(subscriber.getIdentity().getAttributes().getEmail(), events));
    } catch (MailException e) {
        String message = e.getMessage();
        if (message != null && !message.isEmpty() && message.indexOf("Invalid Addresses") > 0) {
            // bypass the retry
            log.error("Invalid Addresses detected !!!", e);
            throw new InvalidAddressException(e);
        }
        throw e;
    }
}
 
开发者ID:huihoo,项目名称:olat,代码行数:20,代码来源:MailChannel.java

示例7: sendVelocityTemplateMailWithAttachment

import org.springframework.mail.MailException; //导入方法依赖的package包/类
private void sendVelocityTemplateMailWithAttachment(final String fromAddress, final List<String> toAddress, final List<String> ccAddress, final String subject,
                                                    final Map<String, Object> modelForMailContent, final String templateName, final boolean isTemplateHtml, final List<MultipartFile> attachFiles) throws Exception {
    MimeMessagePreparator preparator = new MimeMessagePreparator() {
        @Override
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
            helper.setSubject(subject);
            helper.setFrom(fromAddress);
            helper.setTo(toAddress.toArray(new String[toAddress.size()]));
            if (ccAddress != null && ccAddress.size() > 0) {
                helper.setCc(ccAddress.toArray(new String[ccAddress.size()]));
            }

            String text = geVelocityTemplateContent(modelForMailContent, templateName);
            log.debug("Template Name :" + templateName + "Template content : " + text);
            // use the true flag to indicate you need a multipart message
            helper.setText(text, isTemplateHtml);
            for (final MultipartFile attachFile : attachFiles) {
                // determines if there is an upload file, attach it to the e-mail
                if (attachFile != null) {
                    log.info("inside attachFile not null block");
                    String attachName = attachFile.getOriginalFilename();
                    helper.addAttachment(attachName, new InputStreamSource() {
                        @Override
                        public InputStream getInputStream() throws IOException {
                            return attachFile.getInputStream();
                        }
                    });
                } else {
                    log.info("Attached file is Empty. Skipping the file " + attachFile + " in mail.");
                }
            }
        }
    };
    try {
        mailSender.send(preparator);
        log.debug("Template Mail with attachment  successfully sent !! \nFrom Addres: " + fromAddress + " To Address: " + toAddress + " CC Address: " + ccAddress + "\n Subject: " + subject);
    } catch (MailException ex) {
        log.error("Error Sending template Email: " + ex);
        throw new Exception("Error Sending Velocity Template mail with attachment. " + ex.getMessage(), ex);
    }
}
 
开发者ID:Mahidharmullapudi,项目名称:timesheet-upload,代码行数:43,代码来源:EmailServiceImpl.java


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