我需要使用 Postmark 发送带有模板的电子邮件。我的项目没有使用 Postmark 库,而是使用配置了令牌和 url 的 Feign Client。
但是,这种方法使得用数据填充模板变得更加困难。如何将 Spring 应用程序中的数据注入位于resources
文件夹中的模板中?
这是我的假客户端和 dto 类:
@FeignClient(value = "postmark", url = "${email.postmark-url}", configuration = PostmarkConfig.class)
public interface PostmarkFeignClient {
@RequestMapping(method = RequestMethod.POST, consumes = "application/json")
@Headers({"Content-Type: application/json", "Accept: application/json"})
PostmarkResponse sendEmailWithTemplate(@RequestBody PostmarkRequest postmarkRequest);
}
这是 PostmarkRequest:
private String from;
private String to;
private String cc;
private String subject;
private String replyTo;
private String htmlBody;
private String textBody;
private Long templateId;
private Object templateModel;
private String templateAlias;
private boolean inlineCss = true;