Skip to content

Commit 27b6b1e

Browse files
committed
no message
0 parents  commit 27b6b1e

File tree

7 files changed

+128
-0
lines changed

7 files changed

+128
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM einsqing/alpine-node:latest
2+
COPY . /www
3+
WORKDIR /www
4+
RUN yarn global add pm2 && yarn install --production
5+
EXPOSE 465
6+
CMD pm2-runtime start pm2.json

app.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const { SMTPServer } = require("smtp-server");
2+
const server = new SMTPServer({
3+
secure: false,
4+
logger: true,
5+
onConnect(session, callback) {
6+
console.log("onConnect");
7+
console.log(session);
8+
// if(session.remoteAddress === '127.0.0.1'){
9+
// return callback(new Error('No connections from localhost allowed'));
10+
// }
11+
return callback(); // Accept the connection
12+
},
13+
onMailFrom(address, session, callback) {
14+
console.log("onMailFrom");
15+
console.log(address, session);
16+
// if(address.address !== '[email protected]'){
17+
// return callback(new Error('Only [email protected] is allowed to send mail'));
18+
// }
19+
return callback(); // Accept the address
20+
},
21+
onRcptTo(address, session, callback) {
22+
console.log("onRcptTo");
23+
console.log(address, session);
24+
// if(address.address !== '[email protected]'){
25+
// return callback(new Error('Only [email protected] is allowed to receive mail'));
26+
// }
27+
return callback(); // Accept the address
28+
},
29+
onData(stream, session, callback) {
30+
stream.pipe(process.stdout); // print message to console
31+
stream.on("end", callback);
32+
}
33+
});
34+
server.on("error", err => {
35+
console.log("Error %s", err.message);
36+
});
37+
server.listen(465);
38+
console.log("success");

mail.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const nodemailer = require('nodemailer');
2+
3+
function sendEmail(to, subject, html) {
4+
// create reusable transporter object using the default SMTP transport
5+
var transporter = nodemailer.createTransport({
6+
host: "127.0.0.1",
7+
port: 465,
8+
secure: false
9+
});
10+
11+
// setup e-mail data with unicode symbols
12+
var mailOptions = {
13+
from: "[email protected]", // sender address
14+
to: to, // list of receivers
15+
subject: "subject", // Subject line
16+
text: "subject", // plaintext body
17+
html: "xxxx", // html body
18+
replyTo: to
19+
};
20+
21+
// send mail with defined transport object
22+
transporter.sendMail(mailOptions, function(error, info) {
23+
if (error) {
24+
return console.log(error);
25+
}
26+
console.log("Message sent: " + info.response);
27+
});
28+
}
29+
30+
sendEmail("[email protected]", "xxx", "123");

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "mailServer",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"nodemailer": "^4.6.7",
14+
"smtp-server": "^3.4.6"
15+
}
16+
}

pm2.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "smtp",
3+
"script": "app.js",
4+
"watch": false,
5+
"exec_mode": "fork",
6+
"error_file": "./logs/error.log",
7+
"out_file": "./logs/out.log",
8+
"log_date_format": "YYYY-MM-DD HH:mm:ss",
9+
"node_args": [],
10+
"args": [],
11+
"env": {
12+
"NODE_ENV":"docker"
13+
}
14+
}

yarn.lock

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
6+
version "0.1.0"
7+
resolved "https://registry.yarnpkg.com/base32.js/-/base32.js-0.1.0.tgz#b582dec693c2f11e893cf064ee6ac5b6131a2202"
8+
9+
10+
version "1.0.1"
11+
resolved "https://registry.yarnpkg.com/ipv6-normalize/-/ipv6-normalize-1.0.1.tgz#1b3258290d365fa83239e89907dde4592e7620a8"
12+
13+
[email protected], nodemailer@^4.6.7:
14+
version "4.6.7"
15+
resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-4.6.7.tgz#b68de7f36d65618bdeeeb76234e3547d51266373"
16+
17+
smtp-server@^3.4.6:
18+
version "3.4.6"
19+
resolved "https://registry.yarnpkg.com/smtp-server/-/smtp-server-3.4.6.tgz#0f2505158ae42846f55bf374cb1a3386cabcf700"
20+
dependencies:
21+
base32.js "0.1.0"
22+
ipv6-normalize "1.0.1"
23+
nodemailer "4.6.7"

0 commit comments

Comments
 (0)