1

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", "testemailtosend@gmail.com" }
    }
});

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

aBlaze
  • 2,436
  • 2
  • 31
  • 63

3 Answers3

2

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.

aBlaze
  • 2,436
  • 2
  • 31
  • 63
0

Many email servers will "block" when a subject is not present.

Richard Schneider
  • 34,944
  • 9
  • 57
  • 73
  • 1
    However, the subject is already a part of the template. I don't think I should need to specify it again. – aBlaze Apr 25 '18 at 04:39
0

In my case, the provided FromEmail value was not present or activated in the Mailjet Dashboard -> Setup Domain Authentication -> Addresses. For this reason, the response was 200 although the Mailjet service blocked my email.

That's why I didn't receive the mail.