【问题标题】:Filling Postmark template from Java从 Java 填写 Postmark 模板
【发布时间】:2020-08-07 18:26:07
【问题描述】:

我需要使用 Postmark 发送包含模板的电子邮件。我的项目没有使用 Postmark 库,而是使用配置了令牌和 url 的 Feign Client。

但是,这种方法使得用数据填充模板变得更加困难。如何将 Spring 应用程序中的数据注入位于resources 文件夹的模板中?

这是我的 feign 客户端和 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;

【问题讨论】:

    标签: java spring spring-boot feign postmark


    【解决方案1】:

    我了解到我需要将模板发布到 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-30
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多