自定义主题未显示 - {{subject}}

问题描述 投票:0回答:0

我正在通过独立的 Java 程序发送电子邮件请求。但是,发送电子邮件时,主题显示为(无主题)。

我已经创建了一个帐户 创建了一个动态模板 选择了空白模板 想通过 JAVA 代码传递自定义值 在 sendgrid 模板端,我已经像下面提到的那样配置了 {{主题}} 和 {{#each 内容}}

{{this.type}} {{this.value}}

{{/每个}}

当我用测试数据部分(粘贴从独立 java 创建的 json)预览它时,它显示正确的值。 但是当我执行独立程序时,主题和其他内容部分不会显示。

Java代码

import com.sendgrid.Method;
import com.sendgrid.Request;
import com.sendgrid.Response;
import com.sendgrid.SendGrid;
import com.sendgrid.helpers.mail.Mail;
import com.sendgrid.helpers.mail.objects.Content;
import com.sendgrid.helpers.mail.objects.Email;
import com.sendgrid.helpers.mail.objects.Personalization;

import java.io.IOException;


public class WithMailHelper {
    public static void main(String[] args) throws IOException
    {
        Email from = new Email("[email protected]");
        Email to = new Email("[email protected]");
        Content content = new Content("text/plain", "and easy to do anywhere, even with Java");
        Mail mail = new Mail(from, subject, to, content);

        mail.setTemplateId("d-abcdefghijk");
        mail.setSubject("test version of twilio");
        
        mail.addContent(new Content("text/html", "<strong>sendGrid is easy to do anywhere, even with Java</strong>"));

        final Personalization personalization1 = new Personalization();
        personalization1.addTo(new Email("[email protected]", "ABCDEF GHIJK"));
        personalization1.addDynamicTemplateData("name", "ABC");
        personalization1.addDynamicTemplateData("city", "XYZ");
        personalization1.setSubject("testing subject thru personalization");
        mail.addPersonalization(personalization1);

        SendGrid sg = new SendGrid("SG.KEYVALUEPAIRAPI);
        Request request = new Request();
        try {
            request.setMethod(Method.POST);
            request.setEndpoint("mail/send");
            System.out.println(mail.build());
            request.setBody(mail.build());
            Response response = sg.api(request);
            System.out.println("status code: " + response.getStatusCode());
            System.out.println("response body: " + response.getBody());
            System.out.println("response header : " + response.getHeaders());
        } catch (IOException ex) {
            System.out.println("inside exception" + ex.getMessage());
            throw ex;
        }
    }
}

带有自定义主题和内容的电子邮件应该已经显示。但它不是

java twilio sendgrid sendgrid-api-v3
© www.soinside.com 2019 - 2024. All rights reserved.