在Node.js的SendGrid的“from”字段中添加一个名称
我想使用SendGrid API将名称添加到“from”字段,但是我不知道如何执行此操作。 我尝试将sendgrid.send
的“from”参数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); } });
或者你可以创build一个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文档 。 它有如何使用图书馆和它提供的各种function非常详细的信息。
如果您使用的是nodejs Helper库,请使用以下参数:
from_email = new helper.Email("email@domain.com", "Email Name");