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?
Asked
Active
Viewed 1.6k times
5
-
Are you using the sendgrid npm package? – Jeff Sloyer May 07 '15 at 13:07
3 Answers
8
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);
});

Jeff Sloyer
- 4,899
- 1
- 24
- 48
-
I am NOT getting any error, it simply ignores email id set in cc. Also, I am running this code in azure mobile app script, which provides SendGrid module out-of-the-box. – Sajad Deyargaroo Feb 27 '16 at 10:50
-
@SajadDeyargaroo are you plugging in your api keys? Also are you able to send an email when cc was not there? Also what version of the Sendgrid package are you using? – Jeff Sloyer Feb 28 '16 at 11:59
-
I am able to send the email but the things it goes only to emails IDs that are in TO list and email IDs in CC list are ignored. – Sajad Deyargaroo Feb 29 '16 at 17:22
-
is there any solution? I faced the same issue, I am using v6.x.x version. – Subhrajyoti Majumder Dec 02 '20 at 05:55
-
5
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')
}
});

dbburgess
- 751
- 6
- 18

Shaishab Roy
- 16,335
- 7
- 50
- 68
1
If you are using version 7.6.2 of @sendgrid/mail, there is a cc
attribute that works:
import sgMail from '@sendgrid/mail'
sgMail.setApiKey(process.env.SENDGRID_API_KEY)
const msg = {
to: toAddress,
from: fromAddress, // Use the email address or domain you verified above
cc: ccAddress,
subject: `Fresh message from - ${name}`,
text: `A new message was sent by ${name} from ${ccAddress}.
${message}
`,
html: `
<p>hello world</p>
<blockquote>${message}</blockquote>
`,
}
//ES8
try {
await sgMail.send(msg)
return {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
data: 'contactSubmission function',
}),
}
} catch (error) {
console.error(error)
if (error.response) {
console.error(error.response.body)
}
return {
statusCode: 400,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: 'error in email submission',
}),
}
}

brianbancroft
- 463
- 3
- 17