-
Notifications
You must be signed in to change notification settings - Fork 780
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* reply_to_list support is added
- Loading branch information
Showing
5 changed files
with
178 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Multiple emails in replyTo | ||
|
||
An array of recipients who will receive replies and/or bounces. Each object in this array must contain the recipient's email address. Each object in the array may optionally contain the recipient's name. You can either choose to use “reply_to” field or “reply_to_list” but not both. [API specification](https://docs.sendgrid.com/api-reference/mail-send/mail-send#multiple-reply-to-emails) | ||
|
||
```js | ||
const sgMail = require('@sendgrid/mail'); | ||
sgMail.setApiKey(process.env.SENDGRID_API_KEY); | ||
const msg = { | ||
to: '[email protected]', | ||
from: '[email protected]', | ||
subject: 'Multiple mail in replyTo', | ||
html: '<p>Here’s an example of multiple replyTo email for you!</p>', | ||
replyToList: [ | ||
{ | ||
'name': 'Test User1', | ||
'email': '[email protected]' | ||
}, | ||
{ | ||
'email': '[email protected]' | ||
} | ||
], | ||
}; | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,4 +246,62 @@ describe('Mail', function() { | |
expect(logSpy.calledWith(DYNAMIC_TEMPLATE_CHAR_WARNING)).to.equal(true); | ||
}); | ||
}); | ||
|
||
describe('set replyToList to set multiple reply-to', () => { | ||
let data; | ||
|
||
this.beforeEach(() => { | ||
data = { | ||
to: '[email protected]', | ||
from: '[email protected]', | ||
subject: 'test replyToList', | ||
category: 'test', | ||
text: 'Testing replyToList settings', | ||
html: '<p>Testing replyToList settings</p>', | ||
}; | ||
}); | ||
|
||
it('should set the replyToList', () => { | ||
let replyToList = [ | ||
{ | ||
'name': 'Test User1', | ||
'email': '[email protected]' | ||
}, | ||
{ | ||
'email': '[email protected]' | ||
} | ||
]; | ||
data.replyToList = replyToList; | ||
|
||
const mail = new Mail(data); | ||
|
||
expect(mail.replyToList) | ||
.to.be.deep.equal(replyToList); | ||
}); | ||
|
||
it('should throw error for incorrect replyToList format', () => { | ||
let replyToList = [ | ||
{ | ||
'name': 'Test User1' | ||
}, | ||
{ | ||
'email_data': '[email protected]' | ||
} | ||
]; | ||
data.replyToList = replyToList; | ||
|
||
expect(() => new Mail(data)) | ||
.to.throw('Expected each replyTo to contain an `email` string'); | ||
}); | ||
|
||
it('should throw error for as replyToList is not an array', () => { | ||
let replyToList = { | ||
'name': 'Test User1', | ||
'email': '[email protected]' | ||
}; | ||
data.replyToList = replyToList; | ||
expect(() => new Mail(data)) | ||
.to.throw('Array expected for`replyToList`'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ before(() => { | |
* Default mock header | ||
*/ | ||
beforeEach(() => { | ||
sgClient.setDefaultHeader('X-Mock', 200); | ||
sgClient.setDefaultHeader('X-Mock', 202); | ||
}); | ||
|
||
/** | ||
|
@@ -39,11 +39,11 @@ describe('sgMail.send()', () => { | |
}); | ||
|
||
it('should send a basic email', () => { | ||
sgClient.setDefaultHeader('X-Mock', 201); | ||
sgClient.setDefaultHeader('X-Mock', 202); | ||
return sgMail | ||
.send(data) | ||
.then(([response, body]) => { | ||
expect(response.statusCode).to.equal(201); | ||
expect(response.statusCode).to.equal(202); | ||
}); | ||
}); | ||
|
||
|
@@ -54,18 +54,83 @@ describe('sgMail.send()', () => { | |
}); | ||
|
||
it('should include custom headers to the request', () => { | ||
sgClient.setDefaultHeader('X-Mock', 201); | ||
sgClient.setDefaultHeader('X-Mock', 202); | ||
const clientSpy = sinon.spy(sgClient, "request") | ||
return sgMail | ||
.send(Object.assign(data, { headers: { customHeader: "Custom Header Content" } })) | ||
.then(([response, body]) => { | ||
expect(response.statusCode).to.equal(201); | ||
expect(response.statusCode).to.equal(202); | ||
expect(clientSpy).to.have.been.calledWith(sinon.match({ | ||
url: "/v3/mail/send", | ||
method: "POST", | ||
headers: { customHeader: "Custom Header Content" } | ||
})); | ||
}); | ||
}); | ||
|
||
it('should send email with correct replyToList format', () => { | ||
sgClient.setDefaultHeader('X-Mock', 202); | ||
data["replyToList"] = [ | ||
{ | ||
"name": "Test Team", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Support Test Team", | ||
"email": "[email protected]" | ||
} | ||
]; | ||
return sgMail | ||
.send(data) | ||
.then(([response, body]) => { | ||
expect(response.statusCode).to.equal(202); | ||
}); | ||
}); | ||
|
||
it('should throw error with wrong replyToList format', () => { | ||
sgClient.setDefaultHeader('X-Mock', 202); | ||
data["replyToList"] = { | ||
"name": "Support Test Team", | ||
"email": "[email protected]" | ||
}; | ||
return expect(function() { | ||
sgMail.send(data, false, {}); | ||
}).to.throw(Error); | ||
}); | ||
|
||
it('should throw error if any record in replyToList is without email', () => { | ||
data["replyToList"] = [ | ||
{ | ||
"name": "Test Team", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Support Test Team" | ||
} | ||
]; | ||
return expect(function() { | ||
sgMail.send(data, false, {}); | ||
}).to.throw(Error); | ||
}); | ||
|
||
it('should throw error if both replyTo and replyToList are mentioned', () => { | ||
data["replyTo"] = { | ||
"name": "Manual Tester", | ||
"email": "[email protected]" | ||
}; | ||
data["replyToList"] = [ | ||
{ | ||
"name": "Test Team", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Support Test Team", | ||
"email": "[email protected]" | ||
} | ||
]; | ||
return expect(function() { | ||
sgMail.send(data, false, {}); | ||
}).to.throw(Error); | ||
}); | ||
}); | ||
|