我想使用SendGrid API在“来自”字段中添加一个名称,但是我不知道该怎么做。我尝试将“ from”参数设置为sendgrid.sendto,Name <example@example.com>但这没有用。谢谢。
sendgrid.send
Name <example@example.com>
您可以通过两种方式设置from参数:
var SendGrid = require('sendgrid').SendGrid; var sendgrid = new SendGrid(user, key); sendgrid.send({ to: 'you@yourdomain.com', from: 'example@example.com', // Note that we set the `from` parameter here fromname: 'Name', // We set the `fromname` parameter here subject: 'Hello World', text: 'My first email through SendGrid' }, function(success, message) { if (!success) { console.log(message); } });
或者您可以创建一个Email对象并在其上填写以下内容:
Email
var Email = require('sendgrid').Email; var email = new Email({ to: 'you@yourdomain.com', from: 'example@example.com', fromname: 'Name', subject: 'What was Wenger thinking sending Walcott on that early?', text: 'Did you see that ludicrous display last night?' }); sendgrid.send(email, function() { // ... });
您可能需要花几分钟时间浏览Github页面上的README文档。它具有有关如何使用该库及其提供的各种功能的非常详细的信息。