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

时间:2017-07-20 14:44:01

标签: javascript node.js email sendgrid sendgrid-api-v3

是否可以在没有主题的情况下通过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"";,但都返回了错误消息。

任何想法?

1 个答案:

答案 0 :(得分:1)

您无法通过API发送一封空的subject电子邮件。请参阅此处的文档:https://sendgrid.com/docs/API_Reference/api_v3.html

如果向下滚动到主题参数,您会看到它显示:

  

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

它还说它是必需的。如果您查看可以覆盖电子邮件主subject的{​​{1}}的{​​{1}}参数,则会指向此SO主题限制的答案:What is the email subject length limit?

所以基本上这个库的编写方式使得它假设某个主题出现在该地图上并且会出错。

为了测试它,我做了一个像这样的快速卷曲:

personalization

得到了这个回复:

subject
相关问题