How to use the smtp-server.SMTPServer function in smtp-server

To help you get started, we’ve selected a few smtp-server examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github freeCodeCamp / mail-for-good / server / controllers / campaign / email / test-internal / index.js View on Github external
that charge a fee for using their internal test service.

  This test server is not secure and should not be used for any purpose other than debugging.

  See: https://github.com/andris9/smtp-server
*/

const SMTPServer = require('smtp-server').SMTPServer;
const secret = require('../../config/secrets.js');

// Config options & pass to server
const smtpServerOptions = {
  logger: true, // Log to console
  authOptional: true // Authentication is not required
};
const server = new SMTPServer(smtpServerOptions);

// Start the server //
const port = secret.smtpServer.port;
const host = secret.smtpServer.host;

server.listen(port, host);
github Mailtrain-org / mailtrain / services / test-server.js View on Github external
if (!this.accounts[address] || this.accounts[address].length === 0) {
            let err = new Error('No mail for ' + address);
            err.status = 404;
            return callback(err);
        }
        simpleParser(this.accounts[address].shift(), (err, mail) => {
            if (err) {
                return callback(err.message || err);
            }
            callback(null, mail);
        });
    }
};

// Setup server
let server = new SMTPServer({

    // log to console
    logger: config.testserver.logger,

    // not required but nice-to-have
    banner: 'Welcome to My Awesome SMTP Server',

    // disable STARTTLS to allow authentication in clear text mode
    disabledCommands: ['STARTTLS'],

    // By default only PLAIN and LOGIN are enabled
    authMethods: ['PLAIN', 'LOGIN'],

    // Accept messages up to 10 MB
    size: 10 * 1024 * 1024,
github FGRibreau / smtp-to-sendgrid-gateway / server.js View on Github external
const logger = require('winston');
const config = require('./config')(logger);

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(config.sendgrid.api);

const SMTPServer = require('smtp-server').SMTPServer;
const { bufferToSendGridEmail } = require('./utils');
const debug = require('debug')('server');

// start-up the SMTP server (no authentication)
new SMTPServer({
  secure: false,
  disabledCommands: ['AUTH'],
  onData: function(stream, session, callback) {
    let buffer = '';
    let _mail;

    // parse a message as it is received
    stream.setEncoding('utf8');
    stream.on('data', function(part) {
      buffer += part;
    });

    // message fully received
    stream.on('end', function() {
      bufferToSendGridEmail(buffer, session)
        .then(mail => {
github Mailtrain-org / mailtrain / services / verp-server.js View on Github external
'use strict';

let log = require('npmlog');
let config = require('config');
let settings = require('../lib/models/settings');
let campaigns = require('../lib/models/campaigns');
let BounceHandler = require('bounce-handler').BounceHandler;
let SMTPServer = require('smtp-server').SMTPServer;

// Setup server
let server = new SMTPServer({

    // log to console
    logger: false,

    banner: 'Mailtrain VERP bouncer',

    disabledCommands: ['AUTH', 'STARTTLS'],

    onRcptTo: (address, session, callback) => {

        settings.list(['verpHostname'], (err, configItems) => {
            if (err) {
                err = new Error('Failed to load configuration');
                err.responseCode = 421;
                return callback(err);
            }
github JoeBiellik / pleasenospam / mail-server.js View on Github external
const config = require('config');
const SMTPServer = require('smtp-server').SMTPServer;
const MailParser = require('mailparser').simpleParser;
const PassThrough = require('stream').PassThrough;
const sanitize = require('./lib/email-sanitize');
const Email = require('./models/email');

const server = new SMTPServer({
	name: config.mail.hostname,
	banner: config.mail.banner,
	secure: false,
	disabledCommands: ['AUTH', 'STARTTLS'],
	onRcptTo: (address, session, callback) => {
		// Only accept whitelisted recipient address domains
		for (const domain of config.mail.domains) {
			if (address.address.endsWith('@' + domain)) {
				return callback();
			}
		}

		return callback(new Error('Invalid email address'));
	},
	onData: (stream, session, callback) => {
		const original = new PassThrough();
github deitch / smtp-tester / lib / index.js View on Github external
function createSMTPServer(onEmail) {
  return new SMTPServer({
    disabledCommands: [ 'AUTH', 'STARTTLS' ],

    onAuth(auth, session, callback) {
      callback(null);
    },

    onMailFrom(address, session, callback) {
      callback(null);
    },

    onData(stream, session, callback) {
      const chunks = [];

      stream.on('data', function(buffer) {
        chunks.push(buffer);
      });
github nbrownus / streamstash / lib / inputs / SMTPInput.js View on Github external
authOptional: true
        },
        useOptions.smtpOptions
    )

    useOptions.name = options.name || SMTPInput.NAME
    SMTPInput.super_.call(this, useOptions)

    let self = this

    useOptions.smtpOptions.onData = function (stream, session, callback) {
        self._handleInput(stream, session, callback)
    }

    try {
        self.server = new SMTPServer(useOptions.smtpOptions)
    } catch (e) {
        console.log(e)
    }

    self.server.on('error', err => {
        self.logger.error(self.name, 'SMTP Error', { error: err.stack || err })
    })

    self.logger.debug(self.name, 'starting up')

    //TODO: start on start event and not here
    self.server.listen(useOptions.port, useOptions.host)

    self.streamStash.on('start', () => {
        self.state = 1
        self.emit('started')
github internalfx / mailcap / src / server.js View on Github external
co(function *() {
    yield bucket.initBucket()

    var server = new SMTPServer({
      secure: false,
      hideSTARTTLS: true,
      name: 'MAIL CAPTURE SERVER',
      disabledCommands: ['AUTH'],
      onAuth: onAuth,
      onMailFrom: onMailFrom,
      onRcptTo: onRcptTo,
      onData: onData,
      logger: false
    })

    server.listen(config.port)

    console.log('Server Started...')
  })
}
github open-rpa / openflow / OpenFlowNodeRED / src / nodered / nodes / libmailserver.ts View on Github external
return new Promise(async (resolve, reject) => {
            if (libmailserver.current) {
                Logger.instanse.debug('Smtpserver is allready listening on ' + port);
                return resolve(libmailserver.current);
            }

            libmailserver.current = new libmailserver();
            try {
                const SMTPServer = require('smtp-server').SMTPServer;
                libmailserver.current.server = new SMTPServer({
                    secure: false,
                    logger: false,
                    authOptional: true,
                    disableReverseLookup: true,
                    useXClient: true,
                    disabledCommands: ['STARTTLS', 'AUTH'],
                    onMailFrom: libmailserver.current.onMailFrom,
                    onRcptTo: libmailserver.current.onRcptTo,
                    onAuth: libmailserver.current.onAuth,
                    onData: libmailserver.current.onData
                });
                Logger.instanse.info('Smtpserver listening on ' + port);
                await libmailserver.current.server.listen(port);
                resolve(libmailserver.current);
            } catch (err) {
                reject(err);
github emailjs / emailjs-smtp-client / src / client-integration.js View on Github external
before(function (done) {
    server = new SMTPServer({
      port: port,
      authOptional: true
    })
    server.listen(port, done)
  })

smtp-server

Create custom SMTP servers on the fly

MIT-0
Latest version published 1 month ago

Package Health Score

80 / 100
Full package analysis

Popular smtp-server functions