Search in sources :

Example 6 with MimeMailMessage

use of org.springframework.mail.javamail.MimeMailMessage in project cshop by erafaelmanuel.

the class ConfirmationMail method constructMail.

public MimeMailMessage constructMail(Token token, String url, Locale locale) {
    try {
        final String address = messageSource.getMessage(EMAIL, null, locale);
        final String recipientAddress = token.getUser().getEmail();
        final String title = messageSource.getMessage(TITLE, null, locale);
        final Object[] objects = new Object[] { token.getUser().getName(), title };
        final String subject = messageSource.getMessage(MAIL_ACTIVATION, objects, locale);
        final String confirmationUrl = String.format(Locale.ENGLISH, "%s/register/confirmation?token=%s", url, token.getKey());
        MimeMailMessage mailMessage = new MimeMailMessage(mailSender.createMimeMessage());
        mailMessage.setTo(recipientAddress);
        mailMessage.setSubject(subject);
        mailMessage.getMimeMessage().setFrom(new InternetAddress(address, title));
        mailMessage.getMimeMessage().setContent(confirmationUrl, "text/html");
        return mailMessage;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MimeMailMessage(org.springframework.mail.javamail.MimeMailMessage)

Aggregations

MimeMailMessage (org.springframework.mail.javamail.MimeMailMessage)6 MimeMessage (javax.mail.internet.MimeMessage)3 MessagingException (javax.mail.MessagingException)2 MessageMappingException (org.springframework.integration.mapping.MessageMappingException)2 JavaMailSender (org.springframework.mail.javamail.JavaMailSender)2 MessageHandlingException (org.springframework.messaging.MessageHandlingException)2 InternetAddress (javax.mail.internet.InternetAddress)1 ByteArrayResource (org.springframework.core.io.ByteArrayResource)1 MailMessage (org.springframework.mail.MailMessage)1 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)1 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)1 Message (org.springframework.messaging.Message)1