Search code examples
c#sendgrid-api-v3sendgrid-templates

Send email through SendGrid API with Dynamic Template not working


I'm using the C# library for send email with the dynamic template that i'm created. The code that I used I copied from here.

When I executed the code I recived the status code that was Accepted (like I'm showing in the image that I post) enter image description here

but the problem is that the email is not reaching my inbox, and in my SendGrid Dashboard UI the email doesn't appear (is not showing that the email was accepted, or blocked, etc)

In the other hand, if I use the following code, the email is delivered normally and it is in my inbox

var client = new SendGridClient(Options.SendGridKey);
            var msg = new SendGridMessage()
            {
                From = new EmailAddress(email, "Sistema"),
                Subject = asunto,
                //PlainTextContent = message,
                HtmlContent = message,
            };

            msg.AddTo(new EmailAddress(email));

            // Disable click tracking.
            // See https://sendgrid.com/docs/User_Guide/Settings/tracking.html
            msg.SetClickTracking(false, false);

            await client.SendEmailAsync(msg);

Any help? Thanks!!


Solution

  • Try with different from and to email addresses.

    Below code working fine for me since a while.

        var client = new SendGridClient(Options.SendGridKey);
        var from = new EmailAddress("[email protected]", "Name");
        var to = new EmailAddress("[email protected]");
        var msg = MailHelper.CreateSingleTemplateEmail(from, to, templateId, dynamicTemplateData);
        await client.SendEmailAsync(msg);