0

我需要使用 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;
4

1 回答 1

0

我了解到我需要将模板发布到 Postmark 服务器。之后,我可以使用模板 ID 或别名将其与我生成的电子邮件一起使用。

PostmarkRequest mail = new PostmarkRequest();
mail.setFrom(someSender);
mail.setTo(someRecipient);
//Here I put the alias name
mail.setTemplateAlias("my-alias");
mail.setTemplateModel(someModel);
于 2020-05-08T09:46:10.497 回答