Permalink
Browse files

Added XOAUTH2 example

  • Loading branch information...
Andris Reinman
Andris Reinman committed Sep 10, 2012
1 parent 688388b commit a7491f23105a02ac576b375777d236045a4ec2be
Showing with 83 additions and 1 deletion.
  1. +1 −1 README.md
  2. +82 −0 examples/example_xoauth2.js
View
@@ -218,7 +218,7 @@ var transportOptions = {
auth: {
XOAuth2: {
user: "example.user@gmail.com",
- clientId: "8819981768.apps.googleusercontent.comom",
+ clientId: "8819981768.apps.googleusercontent.com",
clientSecret: "{client_secret}",
refreshToken: "1/xEoDL4iW3cxlI7yDbSRFYNG01kVKM2C-259HOF2aQbI"
}
@@ -0,0 +1,82 @@
+var nodemailer = require('../Projects/Nodemailer');
+
+// Create a SMTP transport object
+var transport = nodemailer.createTransport("SMTP", {
+ service: 'Gmail', // use well known service
+ auth: {
+ XOAuth2: {
+ user: "example.user@gmail.com",
+ clientId: "8819981768.apps.googleusercontent.com",
+ clientSecret: "{client_secret}",
+ refreshToken: "1/xEoDL4iW3cxlI7yDbSRFYNG01kVKM2C-259HOF2aQbI"
+ }
+ },
+ debug: true
+ });
+
+console.log('SMTP Configured');
+
+// Message object
+var message = {
+
+ // sender info
+ from: 'Andris Reinman <andris@pipedrive.com>',
+
+ // Comma separated list of recipients
+ to: '"Andris Tahvel" <andris@tahvel.info>',
+
+ // Subject of the message
+ subject: 'Nodemailer is unicode friendly ✔', //
+
+ headers: {
+ 'X-Laziness-level': 1000
+ },
+
+ // plaintext body
+ text: 'Hello to myself!',
+
+ // HTML body
+ html:'<p><b>Hello</b> to myself <img src="cid:note@node"/></p>'+
+ '<p>Here\'s a nyan cat for you as an embedded attachment:<br/><img src="cid:nyan@node"/></p>',
+
+ // An array of attachments
+ attachments:[
+
+ // String attachment
+ {
+ fileName: 'notes.txt',
+ contents: 'Some notes about this e-mail',
+ contentType: 'text/plain' // optional, would be detected from the filename
+ },
+
+ // Binary Buffer attachment
+ {
+ fileName: 'image.png',
+ contents: new Buffer('iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/' +
+ '//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U' +
+ 'g9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC', 'base64'),
+
+ cid: 'note@node' // should be as unique as possible
+ },
+
+ // File Stream attachment
+ {
+ fileName: 'nyan cat ✔.gif',
+ filePath: __dirname+"/nyan.gif",
+ cid: 'nyan@node' // should be as unique as possible
+ }
+ ]
+};
+
+console.log('Sending Mail');
+transport.sendMail(message, function(error){
+ if(error){
+ console.log('Error occured');
+ console.log(error.message);
+ return;
+ }
+ console.log('Message sent successfully!');
+
+ // if you don't want to use this transport object anymore, uncomment following line
+ //transport.close(); // close the connection pool
+});

0 comments on commit a7491f2

Please sign in to comment.