diff options
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 135 |
1 files changed, 66 insertions, 69 deletions
@@ -86,13 +86,6 @@ sendgrid.send(payload, function(err, json) { }); ``` -## Advanced Usage - -There are two additional objects built into this library that will help you use this library as a power user. - -+ Email -+ SmtpapiHeaders - ### Email Email helps you more powerfully prepare your message to be sent. @@ -102,8 +95,7 @@ To get started create an Email object where `params` is a javascript object. You ```javascript var sendgrid = require('sendgrid')(api_user, api_key); -var Email = sendgrid.Email; -var email = new Email(params); +var email = new sendgrid.Email(params); ``` #### Sample @@ -112,8 +104,7 @@ Here is a sample for using it. ```javascript var sendgrid = require('sendgrid')(api_user, api_key); -var Email = sendgrid.Email; -var email = new Email({ +var email = new sendgrid.Email({ to: 'person@somewhere.com', from: 'you@yourself', subject: 'What was Wenger thinking sending Walcott on that early?', @@ -163,8 +154,7 @@ You can set params like you would for any standard JavaScript object. ```javascript var sendgrid = require('sendgrid')(api_user, api_key); -var Email = sendgrid.Email; -var email = new Email({to: 'person@email.com'}); +var email = new sendgrid.Email({to: 'person@email.com'}); email.to = "different@email.com"; email.replyto = "reply-here@email.com"; email.subject = "This is a subject"; @@ -175,7 +165,7 @@ email.subject = "This is a subject"; You can add one or multiple TO addresses using `addTo`. ```javascript -var email = new Email(); +var email = new sendgrid.Email(); email.addTo('foo@bar.com'); email.addTo('another@another.com'); sendgrid.send(email, function(err, json) { }); @@ -186,7 +176,7 @@ NOTE: This is different than setting an array on `to`. The array on `to` will sh #### setFrom ```javascript -var email = new Email(); +var email = new sendgrid.Email(); email.setFrom('foo@bar.com'); sendgrid.send(email, function(err, json) { }); ``` @@ -194,7 +184,7 @@ sendgrid.send(email, function(err, json) { }); #### setSubject ```javascript -var email = new Email(); +var email = new sendgrid.Email(); email.setSubject('Some subject'); sendgrid.send(email, function(err, json) { }); ``` @@ -202,7 +192,7 @@ sendgrid.send(email, function(err, json) { }); #### setText ```javascript -var email = new Email(); +var email = new sendgrid.Email(); email.setText('Some text'); sendgrid.send(email, function(err, json) { }); ``` @@ -210,113 +200,120 @@ sendgrid.send(email, function(err, json) { }); #### setHtml ```javascript -var email = new Email(); +var email = new sendgrid.Email(); email.setHtml('<h1>Some html</h1>'); sendgrid.send(email, function(err, json) { }); ``` -#### setHeaders +#### addHeaders -You can set custom headers. +You can add custom headers. This will ADD rather than SET headers. ```javascript -var email = new Email(); +var email = new sendgrid.Email(); email.setHeaders({full: 'hearts'}); // headers = {full: 'hearts'} -email.setHeaders({mask: 'salesman'}); // headers = {mask: 'salesman'} +email.addHeaders({spin: 'attack'}); // headers = {full: 'hearts', spin: 'attack'} +email.addHeaders({mask: 'salesman'}); // headers = {full: 'hearts', spin: 'attack', mask: 'salesman'} sendgrid.send(email, function(err, json) { }); ``` -#### addHeaders +#### setHeaders -You can add custom headers. This will ADD rather than SET headers. +You can set custom headers. ```javascript -var email = new Email(); +var email = new sendgrid.Email(); email.setHeaders({full: 'hearts'}); // headers = {full: 'hearts'} -email.addHeaders({spin: 'attack'}); // headers = {full: 'hearts', spin: 'attack'} -email.addHeaders({mask: 'salesman'}); // headers = {full: 'hearts', spin: 'attack', mask: 'salesman'} +email.setHeaders({mask: 'salesman'}); // headers = {mask: 'salesman'} sendgrid.send(email, function(err, json) { }); ``` -#### addSubVal +#### addSubstitution ```javascript -var email = new Email(); -email.addSubVal('keep', 'secret'); // sub = {keep: ['secret']} -email.addSubVal('other', ['one', 'two']); // sub = {keep: ['secret'], other: ['one', 'two']} +var email = new sendgrid.Email(); +email.addSubstitution('keep', 'secret'); // sub = {keep: ['secret']} +email.addSubstitution('other', ['one', 'two']); // sub = {keep: ['secret'], other: ['one', 'two']} ``` -#### setSection +#### setSubstitutions ```javascript -var email = new Email(); -email.setSection({'-charge-': 'This ship is useless.'}); // section = {'-charge-': 'This ship is useless.'} +var email = new sendgrid.Email(); +email.setSubstitutions('keep', 'secret'); // sub = {keep: ['secret']} +email.setSubstitutions('other', ['one', 'two']); // sub = {keep: ['secret'], other: ['one', 'two']} ``` #### addSection ```javascript -var email = new Email(); -email.setSection({'-charge-': 'This ship is useless.'}); // section = {'-charge-': 'This ship is useless.'} -email.addSection({'-bomber-': 'Only for sad vikings.'}); // section = {'-charge-': 'This ship is useless.', +var email = new sendgrid.Email(); +email.addSection({'-charge-': 'This ship is useless.'}); // section = {'-charge-': 'This ship is useless.'} ``` -#### setUniqueArgs +#### setSections ```javascript -var email = new Email(); -email.setUniqueArgs({cow: 'chicken'}); // unique_args = {cow: 'chicken'} -email.setUniqueArgs({dad: 'proud'}); // unique_args = {dad: 'proud'} +var email = new sendgrid.Email(); +email.setSections({'-charge-': 'This ship is useless.'}); // section = {'-charge-': 'This ship is useless.'} ``` -#### addUniqueArgs +#### addUniqueArg ```javascript -var email = new Email(); -email.setUniqueArgs({cow: 'chicken'}); // unique_args = {cow: 'chicken'} -email.addUniqueArgs({cat: 'dog'}); // unique_args = {cow: 'chicken', cat: 'dog'} +var email = new sendgrid.Email(); +email.setUniqueArg({cow: 'chicken'}); // unique_args = {cow: 'chicken'} +email.addUniqueArg({cat: 'dog'}); // unique_args = {cow: 'chicken', cat: 'dog'} ``` -#### setFilterSetting - -You can set a filter using an object literal. +#### setUniqueArgs ```javascript -var email = new Email(); -email.setFilterSetting({ - 'footer': { - 'setting': { - 'enable': 1, - 'text/plain': 'You can haz footers!' - } - } -}); +var email = new sendgrid.Email(); +email.setUniqueArgs({cow: 'chicken'}); // unique_args = {cow: 'chicken'} +email.setUniqueArgs({dad: 'proud'}); // unique_args = {dad: 'proud'} ``` -#### setCategory +#### addCategory ```javascript -var email = new Email(); -email.setCategory('tactics'); // category = ['tactics'] -email.setCategory('snowball-fight'); // category = ['snowball-fight'] +var email = new sendgrid.Email(); +email.addCategory('tactics'); // category = ['tactics'] +email.addCategory('advanced'); // category = ['tactics', 'advanced'] ``` -#### addCategory +#### setCategories ```javascript -var email = new Email(); -email.setCategory('tactics'); // category = ['tactics'] -email.addCategory('advanced'); // category = ['tactics', 'advanced'] +var email = new sendgrid.Email(); +email.setCategories(['tactics']); // category = ['tactics'] +email.setCategories(['snowball-fight']); // category = ['snowball-fight'] ``` -#### addFilterSetting +#### addFilter Alternatively, you can add filter settings one at a time. ```javascript -var email = new Email(); -email.addFilterSetting('footer', 'enable', 1); -email.addFilterSetting('footer', 'text/html', '<strong>boo</strong>'); +var email = new sendgrid.Email(); +email.addFilter('footer', 'enable', 1); +email.addFilter('footer', 'text/html', '<strong>boo</strong>'); +``` + +#### setFilters + +You can set a filter using an object literal. + +```javascript +var email = new sendgrid.Email(); +email.setFilters({ + 'footer': { + 'setting': { + 'enable': 1, + 'text/plain': 'You can haz footers!' + } + } +}); ``` #### addFile |