SendGrid - setHtml or setText mandatory even if i use setTemplateId?

Viewed 1012

I'm using SendGrid(https://sendgrid.com/) to send emails from my application. I have query regarding the usage of SendGrid SMTP API.

I'm having SendGrid template,myTemplateId,in which "newPwd" as substitution variable. In java, i defined like this:

SendGrid.Email email=new SendGrid.Email();
email.addTo(toEmailId);
email.setFrom(fromId);
email.setSubject(subject);
email.setTemplateId("myTemplateId");
email.addSubstitution("#newPwd#", new String[]{"myNewPwd"});
SendGrid.Response response=sendGrid.send(email);

When i run this, i'm getting below error response:

{"errors":["Missing email body"],"message":"error"}

If i set, email.setHtml("withsomedummytext") its working fine. But this is displaying the unwanted text in the email body. I don't know how can i avoid this.

But i don't understand why should i set body if i have template which defines body. Am i missing something here? Can anyone please clarify.

I posted the same question in sendgrid community 3days ago. But i dont see any response from community members.

https://community.sendgrid.com/sendgrid/topics/sethtml-or-settext-mandatory-even-if-i-use-settemplateid

So trying here.

1 Answers
Related