本文整理汇总了Java中org.springframework.mail.MailPreparationException类的典型用法代码示例。如果您正苦于以下问题:Java MailPreparationException类的具体用法?Java MailPreparationException怎么用?Java MailPreparationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MailPreparationException类属于org.springframework.mail包,在下文中一共展示了MailPreparationException类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendWithAttachment
import org.springframework.mail.MailPreparationException; //导入依赖的package包/类
@Override
public void sendWithAttachment(String to, String subject, String templateName, Map<String, String> data,
InputStream attachment, String attachmentName) {
try {
File tempFile = File.createTempFile("DummyEmailService-Attachment", attachmentName);
Files.copy(attachment, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
String content = templateService.createTemplate(templateName, data);
String attachmentNotification = "\n### ATTACHMENT: " + tempFile.getAbsolutePath() + " ###\n";
sendMail(to, from, subject, content + attachmentNotification);
} catch (IOException | MailPreparationException e) {
LOG.error("Could not create dummy email from {} to {} with subject {}", from, to, subject, e);
} finally {
IOUtils.closeQuietly(attachment);
}
}
示例2: send
import org.springframework.mail.MailPreparationException; //导入依赖的package包/类
@Override
public void send(final MimeMessagePreparator mimeMessagePreparator) throws MailException
{
final MimeMessage mimeMessage = createMimeMessage();
try
{
mimeMessagePreparator.prepare(mimeMessage);
final String content = (String) mimeMessage.getContent();
final Properties javaMailProperties = getJavaMailProperties();
javaMailProperties.setProperty("mailContent", content);
}
catch (final Exception e)
{
throw new MailPreparationException(e);
}
}
示例3: send
import org.springframework.mail.MailPreparationException; //导入依赖的package包/类
@Override
public void send(final SimpleMailMessage message) throws MailException {
try {
final String content = message.getText();
final Properties javaMailProperties = getJavaMailProperties();
javaMailProperties.setProperty("mailContent", content);
} catch (final Exception e) {
throw new MailPreparationException(e);
}
}
示例4: createTemplate
import org.springframework.mail.MailPreparationException; //导入依赖的package包/类
@Override
public String createTemplate(String templateName, Map<String, ?> data) {
LOG.debug("Creating freemarker template '{}'", templateName);
try {
return FreeMarkerTemplateUtils.processTemplateIntoString(configuration.getTemplate(templateName), data);
} catch (IOException | TemplateException e) {
throw new MailPreparationException("Creating template '" + templateName + "' unsuccessful", e);
}
}
示例5: send
import org.springframework.mail.MailPreparationException; //导入依赖的package包/类
@Override
public void send(final MimeMessagePreparator mimeMessagePreparator) throws MailException {
final MimeMessage mimeMessage = createMimeMessage();
try {
mimeMessagePreparator.prepare(mimeMessage);
final String content = (String) mimeMessage.getContent();
final Properties javaMailProperties = getJavaMailProperties();
javaMailProperties.setProperty("mailContent", content);
} catch (final Exception e) {
throw new MailPreparationException(e);
}
}
示例6: send
import org.springframework.mail.MailPreparationException; //导入依赖的package包/类
@SuppressWarnings("OverloadedVarargsMethod")
@Override
public void send(MimeMessagePreparator... mimeMessagePreparators) throws MailException {
MimeMessage mimeMessage = createMimeMessage();
for (MimeMessagePreparator mimeMessagePreparator : mimeMessagePreparators) {
try {
mimeMessagePreparator.prepare(mimeMessage);
} catch (Exception e) {
throw new MailPreparationException(e);
}
}
send(mimeMessage);
}
示例7: jobSucceedsButMailFails
import org.springframework.mail.MailPreparationException; //导入依赖的package包/类
@Test
public void jobSucceedsButMailFails()
{
doThrow(new MailPreparationException("fail!")).when(mailSender).send(any(SimpleMailMessage.class));
jobExecution.setProgressMessage("Job finished.");
jobExecution.setSuccessEmail("[email protected]");
progress.start();
progress.success();
Mockito.verify(mailSender).send(any(SimpleMailMessage.class));
assertEquals(jobExecution.getProgressMessage(), "Job finished. (Mail not sent: fail!)");
}
示例8: jobFailsAndMailFails
import org.springframework.mail.MailPreparationException; //导入依赖的package包/类
@Test
public void jobFailsAndMailFails()
{
doThrow(new MailPreparationException("fail!")).when(mailSender).send(any(SimpleMailMessage.class));
jobExecution.setProgressMessage("Downloading...");
jobExecution.setFailureEmail("[email protected]");
progress.start();
String exceptionMessage = "x is not a number";
Exception ex = new IllegalArgumentException(exceptionMessage);
progress.failed(ex);
Mockito.verify(mailSender).send(any(SimpleMailMessage.class));
assertEquals(jobExecution.getProgressMessage(), exceptionMessage + " (Mail not sent: fail!)");
}
示例9: jobCanceledAndMailFails
import org.springframework.mail.MailPreparationException; //导入依赖的package包/类
@Test
public void jobCanceledAndMailFails()
{
doThrow(new MailPreparationException("fail!")).when(mailSender).send(any(SimpleMailMessage.class));
jobExecution.setProgressMessage("Downloading...");
jobExecution.setFailureEmail("[email protected]");
progress.start();
progress.canceled();
Mockito.verify(mailSender).send(any(SimpleMailMessage.class));
assertEquals(jobExecution.getProgressMessage(), "Downloading... (Mail not sent: fail!)");
}