All checks were successful
Publish Docker Image / Publish Docker Image (push) Successful in 10s
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
import * as nodemailer from 'nodemailer'
|
|
|
|
interface Options {
|
|
to: string | string[]
|
|
subject: string
|
|
html: string
|
|
text: string
|
|
}
|
|
|
|
const transporter = nodemailer.createTransport({
|
|
host: process.env.SMTP_HOST,
|
|
port: Number(process.env.SMTP_PORT),
|
|
secure: process.env.SMTP_SECURE === 'true',
|
|
auth: {
|
|
user: process.env.SMTP_USER,
|
|
pass: process.env.SMTP_PASSWORD,
|
|
},
|
|
})
|
|
|
|
export const sendEmail = async ({ to, subject, text, html }: Options) =>
|
|
await transporter.sendMail({
|
|
from: `${process.env.FIRST_NAME} ${process.env.LAST_NAME} <${process.env.EMAIL_FROM}>`,
|
|
to: Array.isArray(to) ? to : [to],
|
|
subject,
|
|
text,
|
|
html,
|
|
})
|
|
|
|
export const censorEmail = (email: string): string => {
|
|
const [localPart, domain] = email.split('@')
|
|
|
|
if (localPart.length <= 2) return `${localPart}@${domain}`
|
|
|
|
const firstChar = localPart[0]
|
|
const lastChar = localPart[localPart.length - 1]
|
|
const middleLength = Math.min(localPart.length - 2, 7)
|
|
const middle = '#'.repeat(middleLength)
|
|
|
|
return `${firstChar}${middle}${lastChar}@${domain}`
|
|
}
|