Search in sources :

Example 86 with SimpleMailMessage

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());
    }
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MailException(org.springframework.mail.MailException) ServiceActivator(org.springframework.integration.annotation.ServiceActivator)

Example 87 with SimpleMailMessage

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);
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) AdminUser(uk.ac.bris.cs.rfideasalreadytaken.lumberjack.authentication.data.AdminUser) Logger(org.slf4j.Logger)

Example 88 with SimpleMailMessage

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;
}
Also used : MimeMailMessage(org.springframework.mail.javamail.MimeMailMessage) MailMessage(org.springframework.mail.MailMessage) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MimeMailMessage(org.springframework.mail.javamail.MimeMailMessage) MimeMailMessage(org.springframework.mail.javamail.MimeMailMessage) MailMessage(org.springframework.mail.MailMessage) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MimeMessage(javax.mail.internet.MimeMessage) Message(org.springframework.messaging.Message) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MimeMessage(javax.mail.internet.MimeMessage) MessageHandlingException(org.springframework.messaging.MessageHandlingException)

Example 89 with SimpleMailMessage

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));
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) Test(org.junit.Test)

Example 90 with SimpleMailMessage

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;
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage)

Aggregations

SimpleMailMessage (org.springframework.mail.SimpleMailMessage)106 MailException (org.springframework.mail.MailException)17 Test (org.junit.Test)13 Test (org.testng.annotations.Test)7 Test (org.junit.jupiter.api.Test)6 User (org.molgenis.data.security.auth.User)5 JavaMailSender (org.springframework.mail.javamail.JavaMailSender)5 IOException (java.io.IOException)4 MessagingException (javax.mail.MessagingException)4 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 MailSendException (org.springframework.mail.MailSendException)4 InternetAddress (jakarta.mail.internet.InternetAddress)3 MimeMessage (jakarta.mail.internet.MimeMessage)3 Date (java.util.Date)3 RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)3 MolgenisUserException (org.molgenis.security.user.MolgenisUserException)3 JavaMailSenderImpl (org.springframework.mail.javamail.JavaMailSenderImpl)3 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 User (fr.codechill.spring.model.User)2