Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have use this code
var sendGridClient = new SendGridClient("YOUR_API_KEY");
var sendGridMessage = new SendGridMessage();
sendGridMessage.SetFrom("noreply@example.com", "Example");
sendGridMessage.AddTo("anuraj@example.com");
//The Template Id will be something like this - d-9416e4bc396e4e7fbb658900102abaa2
sendGridMessage.SetTemplateId("YOUR_TEMPLATE_ID");
//Here is the Place holder values you need to replace.
sendGridMessage.SetTemplateData(new
{
    name = "Anuraj",
    url = "https://dotnetthoughts.net"
});

var response = await sendGridClient.SendEmailAsync(sendGridMessage);
if (response.StatusCode == System.Net.HttpStatusCode.Accepted)
{
    //Mail sent
}

Email not send

What I have tried:

<pre>How to send an email with dynamic templates from SendGrid with ASP.NET Core
Posted
Comments
Chris Copeland 13-Sep-21 4:12am    
So what is happening exactly? Is the code throwing an exception; if so, what does the exception tell you is wrong? Is the call to "SendEmailAsync" returning a response with a status code that isn't accepted; if so, what is the status code, have you looked at the documentation to see what it means?

You need to provide us with more context than "Email not send", use your debugger to step through and inspect your code to work out what errors is bring produced, then you can start to work on a solution.
Raju Dhiman 13-Sep-21 5:24am    
var response = await sendGridClient.SendEmailAsync(sendGridMessage);
if (response.StatusCode == System.Net.HttpStatusCode.Accepted)
{
response.StatusCode=accepted
}
Not throw any error. I have debug all code not throw any exception
Chris Copeland 13-Sep-21 6:28am    
If the status code is accepted then there could be many causes for the email not to go through. I would suggest (having used Sendgrid myself in the past) to login to Sendgrid and check the activities to see whether it has marked the email as having been sent. See whether Sendgrid is reporting any problems with finding and/or populating the email template, and whether the delivery status of the email is confirmed.
Raju Dhiman 13-Sep-21 6:54am    
Thanks for this information But I have check activites in send grid not visible any activites .
Thanks
Chris Copeland 13-Sep-21 8:22am    
So there's absolutely nothing in Sendgrid to indicate that it attempted to generate the email, and send it to the email address? And yet your code doesn't produce any errors and it has a response status code of accepted?

Something doesn't add up, either the API is producing an invalid response, or there should be something in Sendgrid to indicate what went wrong. If neither is true then you'll need to raise a support ticket with the Sendgrid team to have them investigate.

Are you sure you've debugged your code and the "response.StatusCode" is accepted?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900