1

我正在使用此处找到的 Ozimov Spring Boot 电子邮件工具

非常容易使用:

@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);
  }

}

现在我只需要发送基本的纯文本电子邮件就可以了。但是,我确实需要能够在我发送的消息中指定自定义邮件类标头。我查看了源代码,但这个库似乎没有这种能力。我希望我错了。这可以做到吗?

4

1 回答 1

2

直到版本 0.5.0,当一个Email对象在EmailService.send()方法中被发送时,它被转换为一个javax.mail.internet.MimeMessage.

我看到在转换中设置了两个标题:Disposition-Notification-To并且Return-Receipt-To分别通过读取Email方法getDepositionNotificationTo()和来设置getReceiptTo()


版本 0.5.1开始,DefaultEmail有一个setCustomHeaders()接收值映射的方法。这应该足以在 MIME 电子邮件中包含自定义标题。

于 2017-03-07T23:34:11.880 回答