繁体   English   中英

发送没有主题的Sendgrid电子邮件

[英]Send Sendgrid Email Without Subject

是否可以通过Sendgrid发送没有主题的电子邮件? 我尝试将主题字段留空,但收到一条错误消息,内容为

TypeError: Cannot read property 'map' of undefined

这是我的代码...

        var helper = require('sendgrid').mail;
        var fromEmail = new helper.Email("myemail@email.com");
        var toEmail = new helper.Email("sendEmail@email.com");

        //I set the subject to null

        var subject = null;

        var content = new helper.Content('text/html', "my message");
        var mail = new helper.Mail(fromEmail, subject, toEmail, content);

        var sg = require('sendgrid')('-----------------');
        var request = sg.emptyRequest({
          method: 'POST',
          path: '/v3/mail/send',
          body: mail.toJSON()
        });

        sg.API(request, function (error, response) {

        });

我尝试将主题设置为null""; 但均返回错误消息。

有任何想法吗?

您不能通过API发送带有空白subject的电子邮件。 在此处查看文档: https : //sendgrid.com/docs/API_Reference/api_v3.html

如果向下滚动到subject参数,您会看到它说:

电子邮件的全局或“邮件级别”主题。 这可能会被个性化设置[x] .subject覆盖。 minLength 1

它还说这是必需的。 如果您查看可以覆盖电子邮件主要subjectpersonalization subject参数,它将指向关于主题限制的SO答案: 什么是电子邮件主题长度限制?

因此,基本上,该库的编写方式是假定该地图上存在一个主题,并且会出错。

为了测试它,我做了如下的快速卷曲:

curl -X POST \
  https://api.sendgrid.com/v3/mail/send \
  -H 'authorization: Bearer MYAPIKEY' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
  "personalizations": [
    {
      "to": [
        {
          "email": "testemail@test.com"
        }
      ],
    }
  ],
  "from": {
    "email": "testemail@test.com"
  },
  "content": [
    {
      "type": "text/plain",
      "value": "Hello, World!"
    }
  ]
}

并得到此响应:

{
    "errors": [
        {
            "message": "The subject is required. You can get around this requirement if you use a template with a subject defined or if every personalization has a subject defined.",
            "field": "subject",
            "help": "http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.subject"
        }
    ]
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM