本文整理汇总了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;
}
示例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;
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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;
}
}
示例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);
}
}