Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Client
- var nodemailer = require('nodemailer');
- // config
- var smtpConfig = {
- host: 'localhost',
- port: 4650,
- secure: false, // dont use SSL
- auth: {
- user: 'user@gmail.com',
- pass: 'pass'
- },
- tls: {rejectUnauthorized: false}
- };
- // create reusable transporter object using the default SMTP transport
- var transporter = nodemailer.createTransport(smtpConfig);
- // setup e-mail data with unicode symbols
- var mailOptions = {
- from: '"Fred Foo 👥" <foo@blurdybloop.com>', // sender address
- to: 'bar@blurdybloop.com, baz@blurdybloop.com', // list of receivers
- subject: 'Hello ✔', // Subject line
- text: 'Hello world 🐴', // plaintext body
- html: '<b>Hello world 🐴</b>' // html body
- };
- // send mail with defined transport object
- transporter.sendMail(mailOptions, function(error, info){
- if(error){
- return console.log(error);
- }
- console.log('Message sent: ' + info.response);
- });
- // Server
- var SMTPServer = require('smtp-server').SMTPServer;
- var server = new SMTPServer({
- onAuth: function(auth, session, callback){
- console.log(auth);
- if(auth.username !== 'abc' || auth.password !== 'def'){
- return callback(new Error('Invalid username or password'));
- }
- callback(null, {user: 123}); // where 123 is the user id or similar property
- },
- onConnect: function(session, callback){
- if(session.remoteAddress === '127.0.0.1'){
- return callback(new Error('No connections from localhost allowed'));
- }
- return callback(); // Accept the connection
- },
- onData: function(stream, session, callback){
- stream.pipe(process.stdout); // print message to console
- stream.on('end', callback);
- }
- });
- server.listen(4650, function() {
- console.log('SMTP Server listening on port ' + 4650);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement