MailJet:HTTP POST状态代码200但电子邮件发送被阻止

时间:2018-04-25 04:17:46

标签: c# mailjet

我在“发送邮件”example here之后使用以下C#代码,使用模板发送包含MailJet的电子邮件。模板有一个变量{{var:name}},它是收件人的名称。

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
}

虽然response.IsStatusSuccessCode等于true,但我的电子邮件一直被阻止。 有人可以解释为什么电子邮件被阻止以及如何解决?

enter image description here

2 个答案:

答案 0 :(得分:1)

问题是我在电子邮件模板中实际上有多个变量,但只指定了其中一个变量。 (这让我感到困惑,因为我确实为其他变量设置了默认值,但事实证明,如果已经指定了所有变量值,MailJet只会发送电子邮件)

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

应该是这个

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

因为电子邮件模板中的其他变量是组织。

答案 1 :(得分:0)

subject不存在时,许多电子邮件服务器将“阻止”。