Guest User

Untitled

a guest
Apr 22nd, 2016
87
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. pass: 'pass'
  11. },
  12. tls: {rejectUnauthorized: false}
  13. };
  14.  
  15. // create reusable transporter object using the default SMTP transport
  16. var transporter = nodemailer.createTransport(smtpConfig);
  17.  
  18. // setup e-mail data with unicode symbols
  19. var mailOptions = {
  20. from: '"Fred Foo 👥" <[email protected]>', // sender address
  21. to: '[email protected], [email protected]', // list of receivers
  22. subject: 'Hello ✔', // Subject line
  23. text: 'Hello world 🐴', // plaintext body
  24. html: '<b>Hello world 🐴</b>' // html body
  25. };
  26.  
  27. // send mail with defined transport object
  28. transporter.sendMail(mailOptions, function(error, info){
  29. if(error){
  30. return console.log(error);
  31. }
  32. console.log('Message sent: ' + info.response);
  33. });
  34.  
  35. // Server
  36. var SMTPServer = require('smtp-server').SMTPServer;
  37.  
  38. var server = new SMTPServer({
  39. onAuth: function(auth, session, callback){
  40. console.log(auth);
  41. if(auth.username !== 'abc' || auth.password !== 'def'){
  42. return callback(new Error('Invalid username or password'));
  43. }
  44. callback(null, {user: 123}); // where 123 is the user id or similar property
  45. },
  46. onConnect: function(session, callback){
  47. if(session.remoteAddress === '127.0.0.1'){
  48. return callback(new Error('No connections from localhost allowed'));
  49. }
  50. return callback(); // Accept the connection
  51. },
  52. onData: function(stream, session, callback){
  53. stream.pipe(process.stdout); // print message to console
  54. stream.on('end', callback);
  55. }
  56. });
  57.  
  58. server.listen(4650, function() {
  59. console.log('SMTP Server listening on port ' + 4650);
  60. });
Advertisement
Add Comment
Please, Sign In to add comment