Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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,
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 => {
'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);
}
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();
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);
});
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')
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...')
})
}
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);
before(function (done) {
server = new SMTPServer({
port: port,
authOptional: true
})
server.listen(port, done)
})