use of org.springframework.mail.SimpleMailMessage in project microservices by pwillhan.
the class MailService method sendMailAlert.
@ServiceActivator(inputChannel = "notifyChannel")
public void sendMailAlert(String body) {
String[] parts = body.split("\\|");
String email = parts[0];
String realbody = parts[1];
logger.info("MailService : " + body);
SimpleMailMessage msg = new SimpleMailMessage();
msg.setTo(email);
msg.setFrom(env.getProperty("com.cassandrawebtrader.mail.from"));
msg.setSubject(env.getProperty("com.cassandrawebtrader.mail.subject"));
msg.setText(realbody);
try {
mailSender.send(msg);
logger.info(msg.toString());
} catch (MailException e) {
logger.error(e.getMessage());
}
}
use of org.springframework.mail.SimpleMailMessage in project lumberjack by fn-ctional.
the class RegistrationListener method confirmRegistration.
private void confirmRegistration(OnRegistrationCompleteEvent event) {
AdminUser adminUser = event.getAdminUser();
String token = UUID.randomUUID().toString();
service.createVerificationToken(adminUser, token);
String recipientAddress = adminUser.getEmail();
String subject = "Registration Confirmation";
String confirmationUrl = event.getAppUrl() + "/registrationConfirm?token=" + token;
String message = "Registration Successful ";
SimpleMailMessage email = new SimpleMailMessage();
email.setTo(recipientAddress);
email.setSubject(subject);
email.setText(message + "<a href=\"" + "http://localhost:8080" + confirmationUrl + "\"\\a>");
email.setFrom(env.getProperty("support.email"));
final Logger log = LoggerFactory.getLogger(LumberjackApplication.class);
log.info("About to send email!");
mailSender.send(email);
}
use of org.springframework.mail.SimpleMailMessage in project spring-integration by spring-projects.
the class MailSendingMessageHandler method convertMessageToMailMessage.
@SuppressWarnings("unchecked")
private MailMessage convertMessageToMailMessage(Message<?> message) {
MailMessage mailMessage = null;
Object payload = message.getPayload();
if (payload instanceof MimeMessage) {
mailMessage = new MimeMailMessage((MimeMessage) payload);
} else if (payload instanceof MailMessage) {
mailMessage = (MailMessage) payload;
} else if (payload instanceof byte[]) {
mailMessage = this.createMailMessageFromByteArrayMessage((Message<byte[]>) message);
} else if (payload instanceof String) {
String contentType = (String) message.getHeaders().get(MailHeaders.CONTENT_TYPE);
if (StringUtils.hasText(contentType)) {
mailMessage = this.createMailMessageWithContentType((Message<String>) message, contentType);
} else {
mailMessage = new SimpleMailMessage();
mailMessage.setText((String) payload);
}
} else {
throw new MessageHandlingException(message, "Unable to create MailMessage from payload type [" + message.getPayload().getClass().getName() + "], " + "expected MimeMessage, MailMessage, byte array or String.");
}
this.applyHeadersToMailMessage(mailMessage, message.getHeaders());
return mailMessage;
}
use of org.springframework.mail.SimpleMailMessage in project spring-integration by spring-projects.
the class MailSendingMessageHandlerContextTests method mailOutboundChannelAdapterWithinChain.
// INT-2275
@Test
public void mailOutboundChannelAdapterWithinChain() {
assertNotNull(this.beanFactory.getBean("org.springframework.integration.handler.MessageHandlerChain#0$child.mail-outbound-channel-adapter-within-chain.handler"));
this.sendMailOutboundChainChannel.send(MailTestsHelper.createIntegrationMessage());
SimpleMailMessage mailMessage = MailTestsHelper.createSimpleMailMessage();
assertEquals("no mime message should have been sent", 0, this.mailSender.getSentMimeMessages().size());
assertEquals("only one simple message must be sent", 1, this.mailSender.getSentSimpleMailMessages().size());
assertEquals("message content different from expected", mailMessage, this.mailSender.getSentSimpleMailMessages().get(0));
}
use of org.springframework.mail.SimpleMailMessage in project spring-integration by spring-projects.
the class MailTestsHelper method createSimpleMailMessage.
public static SimpleMailMessage createSimpleMailMessage() {
SimpleMailMessage message = new SimpleMailMessage();
message.setBcc(BCC);
message.setCc(CC);
message.setTo(TO);
message.setSubject(SUBJECT);
message.setReplyTo(REPLY_TO);
message.setFrom(FROM);
message.setText(MESSAGE_TEXT);
return message;
}
Aggregations