Initial commit

This commit is contained in:
Alex Rennie-Lis
2026-05-01 10:09:51 +01:00
parent e9314ae1e8
commit 299aacd2a4
144 changed files with 39902 additions and 0 deletions

81
node_modules/smtp-server/examples/lmtp.js generated vendored Normal file
View File

@@ -0,0 +1,81 @@
/* eslint no-console: 0 */
'use strict';
// Replace '../lib/smtp-server' with 'smtp-server' when running this script outside this directory
const SMTPServer = require('../lib/smtp-server').SMTPServer;
const SERVER_PORT = 2524;
const SERVER_HOST = '0.0.0.0';
// Connect to this example server by running
// telnet localhost 2524
// or
// nc -c localhost 2524
// Setup server
const server = new SMTPServer({
// log to console
logger: true,
lmtp: true,
// not required but nice-to-have
banner: 'Welcome to My Awesome LMTP Server',
// disable STARTTLS to allow authentication in clear text mode
disabledCommands: ['STARTTLS', 'AUTH'],
// Accept messages up to 10 MB
size: 10 * 1024 * 1024,
// Validate MAIL FROM envelope address. Example allows all addresses that do not start with 'deny'
// If this method is not set, all addresses are allowed
onMailFrom(address, session, callback) {
if (/^deny/i.test(address.address)) {
return callback(new Error('Not accepted'));
}
callback();
},
// Validate RCPT TO envelope address. Example allows all addresses that do not start with 'deny'
// If this method is not set, all addresses are allowed
onRcptTo(address, session, callback) {
let err;
if (/^deny/i.test(address.address)) {
return callback(new Error('Not accepted'));
}
// Reject messages larger than 100 bytes to an over-quota user
if (address.address.toLowerCase() === 'almost-full@example.com' && Number(session.envelope.mailFrom.args.SIZE) > 100) {
err = new Error('Insufficient channel storage: ' + address.address);
err.responseCode = 452;
return callback(err);
}
callback();
},
// Handle message stream
onData(stream, session, callback) {
stream.pipe(process.stdout);
stream.on('end', () => {
let err;
if (stream.sizeExceeded) {
err = new Error('Error: message exceeds fixed maximum message size 10 MB');
err.responseCode = 552;
return callback(err);
}
callback(null, true); // accept the message once the stream is ended
});
}
});
server.on('error', err => {
console.log('Error occurred');
console.log(err);
});
// start listening
server.listen(SERVER_PORT, SERVER_HOST);

81
node_modules/smtp-server/examples/readme.md generated vendored Normal file
View File

@@ -0,0 +1,81 @@
# Basic example
Basic usage example. Create `smtp.js`
```javascript
// smtp.js
const { SMTPServer } = require('smtp-server');
const server = new SMTPServer({
// disable STARTTLS to allow authentication in clear text mode
disabledCommands: ['STARTTLS', 'AUTH'],
logger: true,
onData(stream, session, callback) {
stream.pipe(process.stdout); // print message to console
stream.on('end', callback);
}
});
server.listen(25);
```
Create file `email.txt`. This is email body.
```
Subject: Terminal Email Send
Email Content line 1
Email Content line 2
```
Run in console.
```bash
sudo node smtp.js &
sendmail test@localhost < email.txt
```
You will see something like this:
```
[2016-10-31 11:59:45] INFO: SMTP Server listening on 127.0.0.1:25
[2016-10-31 12:00:01] INFO: [65HrQZWSqi4G] Connection from [127.0.0.1]
[2016-10-31 12:00:01] DEBUG: [65HrQZWSqi4G] S: 220 ubuntu-xenial ESMTP
[2016-10-31 12:00:01] DEBUG: [65HrQZWSqi4G] C: EHLO ubuntu-xenial.localdomain
[2016-10-31 12:00:01] DEBUG: [65HrQZWSqi4G] S: 250-ubuntu-xenial Nice to meet you, [127.0.0.1]
250-PIPELINING
250-8BITMIME
250-SMTPUTF8
250-AUTH LOGIN PLAIN
250 STARTTLS
[2016-10-31 12:00:01] DEBUG: [65HrQZWSqi4G] C: STARTTLS
[2016-10-31 12:00:01] DEBUG: [65HrQZWSqi4G] S: 220 Ready to start TLS
[2016-10-31 12:00:01] INFO: [65HrQZWSqi4G] Connection upgraded to TLS
[2016-10-31 12:00:01] DEBUG: [65HrQZWSqi4G] C: EHLO ubuntu-xenial.localdomain
[2016-10-31 12:00:01] DEBUG: [65HrQZWSqi4G] S: 250-ubuntu-xenial Nice to meet you, [127.0.0.1]
250-PIPELINING
250-8BITMIME
250-SMTPUTF8
250 AUTH LOGIN PLAIN
[2016-10-31 12:00:01] DEBUG: [65HrQZWSqi4G] C: MAIL From:<ubuntu@ubuntu-xenial.localdomain> AUTH=ubuntu@ubuntu-xenial.localdomain
[2016-10-31 12:00:01] DEBUG: [65HrQZWSqi4G] S: 250 Accepted
[2016-10-31 12:00:01] DEBUG: [65HrQZWSqi4G] C: RCPT To:<test@ubuntu-xenial.localdomain>
[2016-10-31 12:00:01] DEBUG: [65HrQZWSqi4G] S: 250 Accepted
[2016-10-31 12:00:01] DEBUG: [65HrQZWSqi4G] C: DATA
[2016-10-31 12:00:01] DEBUG: [65HrQZWSqi4G] S: 354 End data with <CR><LF>.<CR><LF>
Received: (from ubuntu@localhost)
by ubuntu-xenial.localdomain (8.15.2/8.15.2/Submit) id u9VC00kF021723
for test@localhost; Mon, 31 Oct 2016 12:00:00 GMT
Date: Mon, 31 Oct 2016 12:00:00 GMT
From: Ubuntu <ubuntu@ubuntu-xenial.localdomain>
Message-Id: <201610311200.u9VC00kF021723@ubuntu-xenial.localdomain>
Subject: Terminal Email Send
Email Content line 1
Email Content line 2
[2016-10-31 12:00:01] DEBUG: [65HrQZWSqi4G] C: <390 bytes of DATA>
[2016-10-31 12:00:01] DEBUG: [65HrQZWSqi4G] S: 250 OK: message queued
[2016-10-31 12:00:01] DEBUG: [65HrQZWSqi4G] C: QUIT
[2016-10-31 12:00:01] DEBUG: [65HrQZWSqi4G] S: 221 Bye
[2016-10-31 12:00:01] INFO: [65HrQZWSqi4G] Connection closed to [127.0.0.1]
```

115
node_modules/smtp-server/examples/server.js generated vendored Normal file
View File

@@ -0,0 +1,115 @@
/* eslint no-console: 0 */
'use strict';
// Replace '../lib/smtp-server' with 'smtp-server' when running this script outside this directory
const SMTPServer = require('../lib/smtp-server').SMTPServer;
const SERVER_PORT = 2525;
const SERVER_HOST = false;
// Connect to this example server by running
// telnet localhost 2525
// or
// nc -c localhost 2525
// Authenticate with this command (username is 'testuser' and password is 'testpass')
// AUTH PLAIN dGVzdHVzZXIAdGVzdHVzZXIAdGVzdHBhc3M=
// Setup server
const server = new SMTPServer({
// log to console
logger: true,
secure: true,
// not required but nice-to-have
banner: 'Welcome to My Awesome SMTP Server',
// disable STARTTLS to allow authentication in clear text mode
disabledCommands: ['AUTH', 'STARTTLS'],
// By default only PLAIN and LOGIN are enabled
authMethods: ['PLAIN', 'LOGIN', 'CRAM-MD5'],
// Accept messages up to 10 MB
size: 10 * 1024 * 1024,
// allow overriding connection properties. Only makes sense behind proxy
useXClient: true,
hidePIPELINING: true,
// use logging of proxied client data. Only makes sense behind proxy
useXForward: true,
// Setup authentication
// Allow only users with username 'testuser' and password 'testpass'
onAuth(auth, session, callback) {
let username = 'testuser';
let password = 'testpass';
// check username and password
if (
auth.username === username &&
(auth.method === 'CRAM-MD5'
? auth.validatePassword(password) // if cram-md5, validate challenge response
: auth.password === password) // for other methods match plaintext passwords
) {
return callback(null, {
user: 'userdata' // value could be an user id, or an user object etc. This value can be accessed from session.user afterwards
});
}
return callback(new Error('Authentication failed'));
},
// Validate MAIL FROM envelope address. Example allows all addresses that do not start with 'deny'
// If this method is not set, all addresses are allowed
onMailFrom(address, session, callback) {
if (/^deny/i.test(address.address)) {
return callback(new Error('Not accepted'));
}
callback();
},
// Validate RCPT TO envelope address. Example allows all addresses that do not start with 'deny'
// If this method is not set, all addresses are allowed
onRcptTo(address, session, callback) {
let err;
if (/^deny/i.test(address.address)) {
return callback(new Error('Not accepted'));
}
// Reject messages larger than 100 bytes to an over-quota user
if (address.address.toLowerCase() === 'almost-full@example.com' && Number(session.envelope.mailFrom.args.SIZE) > 100) {
err = new Error('Insufficient channel storage: ' + address.address);
err.responseCode = 452;
return callback(err);
}
callback();
},
// Handle message stream
onData(stream, session, callback) {
stream.pipe(process.stdout);
stream.on('end', () => {
let err;
if (stream.sizeExceeded) {
err = new Error('Error: message exceeds fixed maximum message size 10 MB');
err.responseCode = 552;
return callback(err);
}
callback(null, 'Message queued as abcdef'); // accept the message once the stream is ended
});
}
});
server.on('error', err => {
console.log('Error occurred');
console.log(err);
});
// start listening
server.listen(SERVER_PORT, SERVER_HOST);