-
Notifications
You must be signed in to change notification settings - Fork 583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw an exception if a template ID does not exist in your request body #760
Comments
I'll work on this |
Any progress so far? Would also need an endpoint like that. |
@Hantsch Not yet. Pull requests and +1s on the issue summary will help it move up the backlog. |
Hey there, still no plans to this in near future? |
If you are willing to use the StrongGrid C# library instead of SendGrid's own library, you could very easily validate if a given template exists before attempting to send an email. Your code would look something like this: // Validate the templateId
var templateIsValid = false;
try
{
var template = await client.Templates.GetAsync(templateId, null, cancellationToken).ConfigureAwait(false);
templateIsValid = true;
}
catch (SendGridException e) when (e.StatusCode == System.Net.HttpStatusCode.NotFound)
{
// In this context we can safely ignore 'NotFound' exceptions because
// it simply means that the 'templateId' is not valid.
templateIsValid = false;
}
if (templateIsValid)
{
// Send email using a dynamic template
await client.Mail.SendToSingleRecipientAsync(to, from, templateId, cancellationToken: cancellationToken).ConfigureAwait(false);
}
else
{
// Fallback to sending email without a template
await client.Mail.SendToSingleRecipientAsync(to, from, subject, html, text, cancellationToken: cancellationToken).ConfigureAwait(false);
} Hopefully this helps. |
Issue Summary
You will not receive an error from the API is you send an email with the wrong template. Instead you will get a "Not Delivered" notice in your email activity feed. We want to make that experience better by throwing an exception in the code instead.
This issue is inspired by this.
Acceptance Criteria
The text was updated successfully, but these errors were encountered: