mirror of
https://github.com/GithubOrgProjectPiza/server.git
synced 2026-09-04 00:26:07 +02:00
Add basic mail library; Add docker compose
This commit is contained in:
@@ -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
|
||||
Generated
+5345
-4
File diff suppressed because it is too large
Load Diff
@@ -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"
|
||||
},
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import express from "express";
|
||||
import dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const app = express();
|
||||
|
||||
async function main() {
|
||||
|
||||
@@ -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 };
|
||||
Reference in New Issue
Block a user