Add basic mail library; Add docker compose

This commit is contained in:
Stefan-5422
2022-03-02 12:01:28 +01:00
parent c32fffd538
commit 7728776d35
5 changed files with 5413 additions and 4 deletions
+12
View File
@@ -0,0 +1,12 @@
version: "3.4"
services:
mail:
image: boky/postfix
restart: always
environment:
- ALLOWED_SENDER_DOMAINS=mail.${DOMAIN}
ports:
- "587:587"
container_name: "postfix"
volumes:
- ./host/keys/:/etc/opendkim/keys
+5345 -4
View File
File diff suppressed because it is too large Load Diff
+3
View File
@@ -20,7 +20,10 @@
"homepage": "https://github.com/GithubOrgProjectPiza/server#readme",
"dependencies": {
"@types/express": "^4.17.13",
"@types/nodemailer": "^6.4.4",
"dotenv": "^16.0.0",
"express": "^4.17.3",
"nodemailer": "^6.7.2",
"ts-node": "^10.5.0",
"typescript": "^4.5.5"
},
+4
View File
@@ -1,4 +1,8 @@
import express from "express";
import dotenv from "dotenv";
dotenv.config();
const app = express();
async function main() {
+49
View File
@@ -0,0 +1,49 @@
import nodemailer from "nodemailer";
import SMTPTransport from "nodemailer/lib/smtp-transport";
let mailAccount = { user: process.env.MAILUSER + "@mail." + process.env.DOMAIN, pass: process.env.MAILPASSWORD };
let transporter = nodemailer.createTransport(
new SMTPTransport({
host: "localhost",
port: 587,
secure: false,
auth: {
user: mailAccount.user,
pass: mailAccount.pass,
},
tls: {
rejectUnauthorized: false,
secureProtocol: "TLSv1_method",
},
})
);
if (process.env.DEV == "true") {
console.log("test");
(async () => {
mailAccount = await nodemailer.createTestAccount();
console.log(mailAccount);
transporter = nodemailer.createTransport({
host: "smtp.ethereal.email",
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: mailAccount.user, // generated ethereal user
pass: mailAccount.pass, // generated ethereal password
},
});
})();
}
const sendMail = async (from: string, to: string, subject: string, text?: string, html?: string) => {
return await transporter.sendMail({
from: from,
to: to,
subject: subject,
text: text,
html: html,
});
};
export default { sendMail, mailAccount };