sendgrid : add cc in email

隐身守侯 提交于 2021-01-27 14:21:00

问题


I am sending email using sendgrid from my app. Now I want to add cc or bcc if user reply to my mail. How Do I do this. let me explain first. I am sending answer of user's feedback comes on my web application using my application let say I am sending email via 'noreply@mydomain.com', and user receive this mail in his/her inbox in gmail/yahoo or any other email service. In this case user may click reply to this mail. so now, yours 'To:' has contain 'noreply@mydomain.com' default reply address. it's fine. Now I want to add 'cc:' (carbon copy) as follows 'feedback@mydomain.com'. How to do this?


回答1:


You can pass the cc value when calling the sendgrid npm module. See below.

var sendgrid  = require('sendgrid')(api_user, api_key);
var email     = new sendgrid.Email({
  to:       'foo@bar.com',
  from:     'you@yourself.com',
  cc:       'someone@else.com',
  subject:  'Subject goes here',
  text:     'Hello world'
});
sendgrid.send(email, function(err, json) {
  if (err) { return console.error(err); }
  console.log(json);
});



回答2:


For sendGrid V3 you can follow this process to add .

var sgMailHelper = require('sendgrid').mail,
    sg = require('sendgrid')('apiKey');

var sender = new sgMailHelper.Email(sender, senderName||'');
var receiver = new sgMailHelper.Email(receiver);
var content = new sgMailHelper.Content("text/plain", "Test mail");
var subject = "Mail subject";

var mailObj = new sgMailHelper.Mail(sender, subject, receiver, content);

// add cc email
mailObj.personalizations[0].addCc(new sgMailHelper.Email('cc.email@gmail.com'));

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

sg.API(request, function(error, response) {
        if(error) {         
          console.log(error)
        } else {
          console.log('success')
        }
      });


来源:https://stackoverflow.com/questions/30099882/sendgrid-add-cc-in-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!