File tree Expand file tree Collapse file tree 3 files changed +42
-17
lines changed Expand file tree Collapse file tree 3 files changed +42
-17
lines changed Original file line number Diff line number Diff line change 13
13
"googleapis" : " ^12.2.0" ,
14
14
"nodemailer" : " ^2.4.1" ,
15
15
"nodemailer-smtp-transport" : " ^2.5.0" ,
16
- "sendgrid" : " ^2 .0.0 "
16
+ "sendgrid" : " ^4 .0.1 "
17
17
},
18
18
"devDependencies" : {
19
19
"mocha" : " ^3.0.2"
Original file line number Diff line number Diff line change 14
14
'use strict' ;
15
15
16
16
// [START send]
17
+ // This sample is based off of https://www.npmjs.com/package/sendgrid#without-mail-helper-class
17
18
var Sendgrid = require ( 'sendgrid' ) (
18
19
process . env . SENDGRID_API_KEY || '<your-sendgrid-api-key>'
19
20
) ;
20
21
21
- Sendgrid . send ( {
22
- from : 'ANOTHER_EMAIL@ANOTHER_EXAMPLE.COM' , // From address
23
- to : 'EMAIL@EXAMPLE.COM' , // To address
24
- subject : 'test email from Node.js on Google Cloud Platform' , // Subject
25
- text : 'Hello!\n\nThis a test email from Node.js.' // Content
26
- } , function ( err , json ) {
27
- if ( err ) {
28
- return console . log ( err ) ;
22
+ var request = Sendgrid . emptyRequest ( {
23
+ method : 'POST' ,
24
+ path : '/v3/mail/send' ,
25
+ body : {
26
+ personalizations : [ {
27
+ to : [ { email : 'to_email@example.com' } ] ,
28
+ subject : 'Sendgrid test email from Node.js on Google Cloud Platform'
29
+ } ] ,
30
+ from : { email : 'from_email@example.com' } ,
31
+ content : [ {
32
+ type : 'text/plain' ,
33
+ value : 'Hello!\n\nThis a Sendgrid test email from Node.js on Google Cloud Platform.'
34
+ } ]
29
35
}
30
- console . log ( json ) ;
36
+ } ) ;
37
+
38
+ Sendgrid . API ( request , function ( error , response ) {
39
+ if ( error ) {
40
+ console . log ( 'Mail not sent; see error message below.' ) ;
41
+ } else {
42
+ console . log ( 'Mail sent successfully!' ) ;
43
+ }
44
+ console . log ( response ) ;
31
45
} ) ;
32
46
// [END send]
Original file line number Diff line number Diff line change @@ -22,14 +22,25 @@ describe('computeengine:sendgrid', function () {
22
22
sendgrid : function ( key ) {
23
23
assert . equal ( key , 'foo' ) ;
24
24
return {
25
- send : function ( payload , cb ) {
26
- assert . deepEqual ( payload , {
27
- from : 'ANOTHER_EMAIL@ANOTHER_EXAMPLE.COM' ,
28
- to : 'EMAIL@EXAMPLE.COM' ,
29
- subject : 'test email from Node.js on Google Cloud Platform' ,
30
- text : 'Hello!\n\nThis a test email from Node.js.'
25
+ emptyRequest : function ( x ) {
26
+ return x ;
27
+ } ,
28
+ API : function ( request , cb ) {
29
+ assert . deepEqual ( request , {
30
+ method : 'POST' ,
31
+ path : '/v3/mail/send' ,
32
+ body : {
33
+ personalizations : [ {
34
+ to : [ { email : 'to_email@example.com' } ] ,
35
+ subject : 'Sendgrid test email from Node.js on Google Cloud Platform'
36
+ } ] ,
37
+ from : { email : 'from_email@example.com' } ,
38
+ content : [ {
39
+ type : 'text/plain' ,
40
+ value : 'Hello!\n\nThis a Sendgrid test email from Node.js on Google Cloud Platform.'
41
+ } ]
42
+ }
31
43
} ) ;
32
- cb ( 'done' ) ;
33
44
done ( ) ;
34
45
}
35
46
} ;
You can’t perform that action at this time.
0 commit comments