sendgrid:在电子邮件中添加抄送

问题描述:

我正在通过我的应用程序使用sendgrid发送电子邮件.现在,如果用户回复我的邮件,我想添加抄送或密件抄送.我该怎么做呢.让我先解释一下.我正在使用我的应用程序在我的Web应用程序上发送用户反馈的答复,说我正在通过"noreply@mydomain.com"发送电子邮件,并且用户在其收件箱中的gmail/yahoo或任何其他电子邮件服务中收到此邮件.在这种情况下,用户可以单击对此邮件的回复.所以现在,您的收件人:"包含默认的回复地址"noreply@mydomain.com".没关系.现在,我想在"feedback@mydomain.com"之后添加"cc:"(抄本).这该怎么做?

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?

对于 sendGrid V3 ,您可以按照此过程进行添加.

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')
        }
      });