use of org.springframework.mail.SimpleMailMessage in project spring-framework by spring-projects.
the class JavaMailSenderTests method javaMailSenderWithParseExceptionOnSimpleMessage.
@Test
public void javaMailSenderWithParseExceptionOnSimpleMessage() {
MockJavaMailSender sender = new MockJavaMailSender();
SimpleMailMessage simpleMessage = new SimpleMailMessage();
simpleMessage.setFrom("");
try {
sender.send(simpleMessage);
} catch (MailParseException ex) {
// expected
boolean condition = ex.getCause() instanceof AddressException;
assertThat(condition).isTrue();
}
}
use of org.springframework.mail.SimpleMailMessage in project paascloud-master by paascloud.
the class OptSendMailServiceImpl method sendSimpleMail.
@Override
public int sendSimpleMail(String subject, String text, Set<String> to) {
log.info("sendSimpleMail - 发送简单邮件. subject={}, text={}, to={}", subject, text, to);
int result = 1;
try {
SimpleMailMessage message = MailEntity.createSimpleMailMessage(subject, text, to);
message.setFrom(from);
taskExecutor.execute(() -> mailSender.send(message));
} catch (Exception e) {
log.info("sendSimpleMail [FAIL] ex={}", e.getMessage(), e);
result = 0;
}
return result;
}
use of org.springframework.mail.SimpleMailMessage in project uhgroupings by uhawaii-system-its-ti-iam.
the class EmailServiceTest method sendFeedbackWithMailExceptionThrown.
@Test
public void sendFeedbackWithMailExceptionThrown() {
JavaMailSender senderWithException = new MockJavaMailSender() {
@Override
public void send(SimpleMailMessage mailMessage) throws MailException {
wasSent = false;
throw new MailSendException("Exception");
}
};
EmailService emailServiceWithException = new EmailService(senderWithException);
emailServiceWithException.setEnabled(true);
Feedback feedback = createBaseFeedback();
emailServiceWithException.send(feedback);
assertThat(wasSent, is(false));
}
use of org.springframework.mail.SimpleMailMessage in project uhgroupings by uhawaii-system-its-ti-iam.
the class EmailServiceTest method setUp.
@Before
public void setUp() {
JavaMailSender sender = new MockJavaMailSender() {
@Override
public void send(SimpleMailMessage mailMessage) throws MailException {
wasSent = true;
messageSent = mailMessage;
}
};
emailService = new EmailService(sender);
emailService.setEnabled(true);
wasSent = false;
}
use of org.springframework.mail.SimpleMailMessage in project uhgroupings by uhawaii-system-its-ti-iam.
the class EmailService method send.
public void send(Feedback feedback) {
logger.info("Feedback received in EmailService: " + feedback);
if (isEnabled) {
SimpleMailMessage msg = new SimpleMailMessage();
msg.setTo(to);
msg.setFrom(from);
String text = "";
String header = "UH Groupings service feedback [" + feedback.getType() + "]";
text += "Submitted name: " + feedback.getName() + "\n\n";
text += "Submitted email: <" + feedback.getEmail() + ">\n\n";
text += "Feedback type: " + feedback.getType() + "\n\n";
text += "--------------------------" + "\n\n";
text += "Feedback: " + feedback.getMessage() + "\n\n";
if (!feedback.getExceptionMessage().isEmpty()) {
text += "Stack Trace: " + feedback.getExceptionMessage();
}
msg.setText(text);
msg.setSubject(header);
try {
javaMailSender.send(msg);
} catch (MailException ex) {
logger.error("Error", ex);
}
}
}
Aggregations