1

I'm using the Ozimov Spring Boot Email Tools found here

Very easy to use:

@Service
public class TestService {

@Autowired
private EmailService emailService;

public void sendEmail() throws UnsupportedEncodingException {
    final Email email = DefaultEmail.builder()
            .from(new InternetAddress("hari.seldon@the-foundation.gal",
                    "Hari Seldon"))
            .to(newArrayList(
                    new InternetAddress("the-real-cleon@trantor.gov",
                    "Cleon I")))
            .subject("You shall die! It's not me, it's Psychohistory")
            .body("Hello Planet!")
            .encoding("UTF-8").build();

    emailService.send(email);
  }

}

For now I just need to send basic, plain text email and I have that working. However, I really need to be able to specify custom mail class headers in my sent messages. I looked through the source but this library does not seem to have that capability. I'm hoping I'm wrong. Can this be done?

JeanValjean
  • 17,172
  • 23
  • 113
  • 157
Jim Archer
  • 1,337
  • 5
  • 30
  • 43
  • First time I hear about ozimov. I agree, looks like it does not support the headers. The workaround could be intercept a call to `mailSender.send` and add the header there. But personally I would not be comfortable with that. I would probably just use `MailSender` directly. Not sure how much ozimov buys you for plain text messages – jny Mar 07 '17 at 22:33
  • Which headers should you add? – JeanValjean Mar 07 '17 at 23:27
  • For right now it does not get me much, however I'll need the template capability very soon (like this week) and the ability to easily send MIME emails soon. It seems like a well done bit of work. – Jim Archer Mar 08 '17 at 00:30
  • @JeanValjean We send a lot of email to customers, and to archive them we set custom headers that identify the class of mail. By that, I mean it's a mail that notifies a customer about one thing or another and each notification message type has a unique header. These notifications are mandated by a regulatory agency so we need to archive them to prove they were sent. We do this by BCCing the message to an archive server that reads these special headers and sorts the message accordingly. – Jim Archer Mar 08 '17 at 00:39

1 Answers1

2

Up to version 0.5.0, when an Email object is sent in the EmailService.send() method it gets converted into a javax.mail.internet.MimeMessage.

I see two headers set in the conversion: Disposition-Notification-To and Return-Receipt-To which are set by reading via the Email methods getDepositionNotificationTo() and getReceiptTo(), respectively.


From release 0.5.1, DefaultEmail has a method setCustomHeaders() that receives a map of values. This should be enough to have custom headers in the MIME email.

JeanValjean
  • 17,172
  • 23
  • 113
  • 157
  • Thank you @JeanValijean for the quick response. I'm not at all familiar with the existing interfaces but I'll take a deeper look. If I can I'll see if I can implement it but I'm under the gun to get something into production. I'll see if I can do a feature request, because even if I have to move to something else in the very short term I would like to return to this. You did a nice job with it, thank you! – Jim Archer Mar 08 '17 at 00:35
  • @JimArcher release 0.5.1 handled this feature request, but is currently in Maven Central Repository staging. – JeanValjean Mar 08 '17 at 07:50
  • Wow @JeanValijean amazing, thank you! It's way past my bedtime, I'll check this out Wednesday. I'll figure out about staging. Thanks again! – Jim Archer Mar 08 '17 at 08:09
  • @JimArcher I mean, the staging environment takes a while before that the artifact get published. Usually a couple of hours. So after that period one can just try to import the new dependency version from Maven Central. – JeanValjean Mar 08 '17 at 10:28