向“添加名称”;从「;Node.js中SendGrid中的字段

向“添加名称”;从「;Node.js中SendGrid中的字段,node.js,sendgrid,Node.js,Sendgrid,我想使用SendGrid API向我的“发件人”字段添加一个名称,但我不知道如何做到这一点。我尝试在sendgrid中设置“from”参数。将发送到Name,但没有成功。谢谢。您可以通过以下几种方式设置from参数: var SendGrid = require('sendgrid').SendGrid; var sendgrid = new SendGrid(user, key); sendgrid.send({ to: 'you@yourdomain.com', from: 'exa

我想使用SendGrid API向我的“发件人”字段添加一个名称,但我不知道如何做到这一点。我尝试在
sendgrid中设置“from”参数。将
发送到
Name
,但没有成功。谢谢。

您可以通过以下几种方式设置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);
  }
});
或者您可以创建一个
电子邮件
对象并填写以下内容:

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() { 
  // ... 
});

你可能需要花几分钟的时间来回顾一下。它提供了关于如何使用该库及其提供的各种功能的详细信息。

如果您使用的是nodejs Helper库,请使用以下参数:

from_email = new helper.Email("email@domain.com", "Email Name");

使用最新版本中使用的语法更新了示例


尽管更新的用例不包括from

这个对我有用

  to: 'user@userdomain.com',
  from: {
      name: 'Sender'
      email: 'me@mydomain.com',
  },
  subject: 'Hello World',
  html: `<html><p>Hello World</p></html>`
});
to:'user@userdomain.com',
发件人:{
名称:“发件人”
电邮:'me@mydomain.com',
},
主题:“你好,世界”,
html:`helloworld

` });
从节点库上的github,您可以使用以下任一方法发送电子邮件和姓名

from: {
   name: 'Name Here',
   email: 'email here'
}

from:“酷名”

谢谢。我阅读了自述文件,出于某种原因,在试图查找相关信息时,我没有看到文档中的
fromname
字段。下次我将尝试Ctrl+F:)什么是用户和键。我认为is键就是api键,但什么是用户键呢?这是用户名或其他任何名称。这不再有效。请参阅下面的“焚化炉答案”。这已经不起作用了。看答案。@Swift这已经不起作用了。你能在回答中提到这一点吗?谢谢你,同样的问题,我在文档中找不到
名称
字段,事实上文档并不特别容易浏览。我同意。我已经发布了一个文件,试图在文档中澄清这一点,但到目前为止没有任何效果。不知道几个月前是否是这样,但现在有文档记录了这一点。我在这里找到了文档。这应该是Sendgrid API V3的公认答案。非常好的答案!
from: {
   name: 'Name Here',
   email: 'email here'
}
from: "Cool Name <some@email.com>"