Reputation: 381
I would like to know, what's the proper way to use SendGrid templates in C#? Now im getting the following error:
The error detected was: Templates error: 'http_get returned non-20x response: '404 Not Found' body='{"error": "active version not found"}'
Here's my EmailService class, which i would like to use to send emails to users. If i comment out "EnableTemplateEngine" method, everything seems to work but i'd really like to use SendGrid templates.
public class EmailService : IIdentityMessageService
{
public async Task SendAsync(IdentityMessage message)
{
await configSendGridasync(message);
}
private async Task configSendGridasync(IdentityMessage message)
{
var myMessage = new SendGridMessage();
myMessage.AddTo(message.Destination);
myMessage.From = new System.Net.Mail.MailAddress("emailAddress", "displayName");
myMessage.Subject = message.Subject;
myMessage.Text = message.Body;
myMessage.Html = message.Body;
myMessage.EnableTemplateEngine("eeeexxxx-aaaa-mmmm-pppp-lllleeee1234");
...
}
}
SendGrid Activity Log shows that email was dropped and the reason was "Invalid SMTP Header"
Upvotes: 4
Views: 6364
Reputation: 1511
If you're getting the Active Version Not Found error then you need to make the template that you want to use active via the SendGrid Template Engine Dashboard first. Once you have an active template under the ID you are using, it should work fine.
More details are in the User Guide for Template Engine.
Upvotes: 5