Search code examples
c#mailjet

MailJet: HTTP POST status code 200 but email sending is blocked


I am using the following C# code following the "Send a mail" example here to send an email with MailJet using a template. The template has a variable {{var:name}} which is the name of the recipient.

int templateID = 610379;

MailjetRequest request = new MailjetRequest
{
    Resource = Send.Resource,
}
.Property(Send.FromEmail, ConfigurationManager.AppSettings["MailJetFromEmail"].ToString())
.Property(Send.FromName, "Support Team")
.Property(Send.MjTemplateID, templateID)
.Property(Send.MjTemplateLanguage, true)
.Property(Send.Vars, new JArray
{
    new JObject
    {
        { "name", "Name of the customer"}
    }
})
.Property(Send.Recipients, new JArray
{
    new JObject
    {
        { "Email", "[email protected]" }
    }
});

MailjetResponse response = await client.PostAsync(request);

if (response.IsSuccessStatusCode)
{
    // Log success
}
else
{
    // Log error
}

While response.IsStatusSuccessCode does equal true, my email is consistently getting blocked. Can someone please explain why the email is getting blocked and how to fix it?

enter image description here


Solution

  • The issue was that I actually had multiple Variables in the email template, but was only specifying one of them. (This was confusing to me because I did set default values for those other variables, but it turns out that MailJet only sends the email if ALL of the variables' values have been specified)

    This

    .Property(Send.Vars, new JArray
    {
        new JObject
        {
            { "name", "Name of the customer" }
        }
    })
    

    should have been this

    .Property(Send.Vars, new JArray
    {
        new JObject
        {
            { "name", "Name of the customer" }
            { "org", "Organization of the customer" }
        }
    })
    

    because the other variable in the email template was the organization.