Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ const cli = require('cli').enable('catchall').enable('status');

const config = cli.parse({
'smtp-port': ['s', 'SMTP port to listen on', 'number', 1025],
'smtp-ip': [false, 'IP Address to bind SMTP service to', 'ip', '0.0.0.0'],
'smtp-ip': ['i', 'IP Address to bind SMTP service to', 'ip', '0.0.0.0'],
'http-port': ['h', 'HTTP port to listen on', 'number', 1080],
'http-ip': [false, 'IP Address to bind HTTP service to', 'ip', '0.0.0.0'],
'http-ip': ['p', 'IP Address to bind HTTP service to', 'ip', '0.0.0.0'],
whitelist: ['w', 'Only accept e-mails from these adresses. Accepts multiple e-mails comma-separated', 'string'],
max: ['m', 'Max number of e-mails to keep', 'number', 100],
auth: ['a', 'Enable Authentication', 'string'],
headers: [false, 'Enable headers in responses']
});

const whitelist = config.whitelist ? config.whitelist.split(',') : [];
const emailErrors = []

let users = null;
if (config.auth && !/.+:.+/.test(config.auth)) {
Expand All @@ -38,6 +39,13 @@ const server = new SMTPServer({
authOptional: true,
maxAllowedUnauthenticatedCommands: 1000,
onMailFrom(address, session, cb) {
if (emailErrors.length > 0) {
const isError = emailErrors.shift()

if (isError)
cb(new Error('Failed to send mail'))
}

if (whitelist.length == 0 || whitelist.indexOf(address.address) !== -1) {
cb();
} else {
Expand Down Expand Up @@ -96,6 +104,8 @@ server.listen(config['smtp-port'], config['smtp-ip']);

const app = express();

app.use(express.json())

app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
Expand Down Expand Up @@ -137,6 +147,11 @@ function emailFilter(filter) {
}
}

app.post('/api/emails/errors', (req, res) => {
emailErrors.push(...req.body.errors)
res.send()
})

app.get('/api/emails', (req, res) => {
res.json(mails.filter(emailFilter(req.query)));
});
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@
},
"dependencies": {
"cli": "1.0.1",
"express": "4.16.4",
"express-basic-auth": "1.1.6",
"lodash": "4.17.11",
"mailparser": "2.4.3",
"moment": "2.24.0",
"smtp-server": "3.5.0"
"express": "4.18.2",
"express-basic-auth": "1.2.1",
"lodash": "4.17.21",
"mailparser": "3.5.0",
"moment": "2.29.4",
"smtp-server": "3.11.0"
},
"devDependencies": {
"react": "16.8.3",
"react-dom": "16.8.3",
"react-scripts": "2.1.5",
"react-transition-group": "2.6.0",
"reactstrap": "7.1.0"
"react": "18.2.0",
"react-dom": "18.2.0",
"react-scripts": "5.0.1",
"react-transition-group": "4.4.5",
"reactstrap": "9.1.4"
},
"engines": {
"node": ">=8.5.0"
Expand Down