Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. // Client
  2. var nodemailer = require('nodemailer');
  3.  
  4. // config
  5. var smtpConfig = {
  6. host: 'localhost',
  7. port: 4650,
  8. secure: false, // dont use SSL
  9. auth: {
  10. user: 'user@gmail.com',
  11. pass: 'pass'
  12. },
  13. tls: {rejectUnauthorized: false}
  14. };
  15.  
  16. // create reusable transporter object using the default SMTP transport
  17. var transporter = nodemailer.createTransport(smtpConfig);
  18.  
  19. // setup e-mail data with unicode symbols
  20. var mailOptions = {
  21. from: '"Fred Foo 👥" <foo@blurdybloop.com>', // sender address
  22. to: 'bar@blurdybloop.com, baz@blurdybloop.com', // list of receivers
  23. subject: 'Hello ✔', // Subject line
  24. text: 'Hello world 🐴', // plaintext body
  25. html: '<b>Hello world 🐴</b>' // html body
  26. };
  27.  
  28. // send mail with defined transport object
  29. transporter.sendMail(mailOptions, function(error, info){
  30. if(error){
  31. return console.log(error);
  32. }
  33. console.log('Message sent: ' + info.response);
  34. });
  35.  
  36. // Server
  37. var SMTPServer = require('smtp-server').SMTPServer;
  38.  
  39. var server = new SMTPServer({
  40. onAuth: function(auth, session, callback){
  41. console.log(auth);
  42. if(auth.username !== 'abc' || auth.password !== 'def'){
  43. return callback(new Error('Invalid username or password'));
  44. }
  45. callback(null, {user: 123}); // where 123 is the user id or similar property
  46. },
  47. onConnect: function(session, callback){
  48. if(session.remoteAddress === '127.0.0.1'){
  49. return callback(new Error('No connections from localhost allowed'));
  50. }
  51. return callback(); // Accept the connection
  52. },
  53. onData: function(stream, session, callback){
  54. stream.pipe(process.stdout); // print message to console
  55. stream.on('end', callback);
  56. }
  57. });
  58.  
  59. server.listen(4650, function() {
  60. console.log('SMTP Server listening on port ' + 4650);
  61. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement