Files
quicklanch-server/src/app/utils/mail_sender.ts
T

124 lines
2.9 KiB
TypeScript
Raw Normal View History

2026-04-02 21:27:09 +06:00
import nodemailer from 'nodemailer';
import { configs } from '../configs';
2026-04-02 21:27:09 +06:00
type TMailContent = {
2026-04-12 22:47:56 +06:00
to: string,
subject: string,
textBody: string,
htmlBody: string,
name?: string
2026-04-02 21:27:09 +06:00
}
const transporter = nodemailer.createTransport({
2026-04-12 22:47:56 +06:00
host: "smtp.gmail.com",
port: 465,
secure: true, // true for 465, false for other ports
auth: {
user: configs.email.app_email!,
pass: configs.email.app_password!,
},
2026-04-02 21:27:09 +06:00
});
// ✅ Email Sender Function
const sendMail = async (payload: TMailContent) => {
2026-04-12 22:47:56 +06:00
const info = await transporter.sendMail({
from: 'info@digitalcreditai.com',
to: payload.to,
subject: payload.subject,
text: payload.textBody,
html: `
<!doctype html>
2026-04-02 21:27:09 +06:00
<html lang="en">
<head>
<meta charset="UTF-8" />
2026-04-02 21:27:09 +06:00
<title>Welcome Email</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
2026-04-02 21:27:09 +06:00
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
2026-04-02 21:27:09 +06:00
/* Fallback styles for unsupported clients (some email clients ignore <style> tags) */
@media only screen and (max-width: 600px) {
.container {
padding: 20px !important;
}
2026-04-02 21:27:09 +06:00
.btn {
padding: 12px 18px !important;
font-size: 16px !important;
2026-04-02 21:27:09 +06:00
}
}
2026-04-02 21:27:09 +06:00
</style>
</head>
2026-04-02 21:27:09 +06:00
<body style="margin: 0; padding: 0; font-family: Arial, sans-serif">
<div
style="
max-width: 600px;
margin: 40px auto;
background-color: #f4f4f4;
padding: 40px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
"
class="container"
>
<div style="font-size: 16px; color: #555555; line-height: 1.6">
<p style="margin-bottom: 30px">
Hi <strong>${payload?.name || ""}</strong>,
2026-04-02 21:27:09 +06:00
</p>
${payload?.htmlBody}
<div style="margin-top: 60px; text-align: center">
<img
style="width: 50px; height: 50px; border-radius: 50%"
src="https://i.ibb.co.com/RkFJjPWg/quick-launch-1.png"
alt="Quick Launch"
/>
<p style="font-size: 12px">The Support Team</p>
<h3>Quick Launch</h3>
2026-04-02 21:27:09 +06:00
</div>
</div>
<p
style="
font-size: 14px;
color: #999999;
margin-top: 20px;
margin-bottom: 10px;
text-align: center;
"
>
This is an automated message — please do not reply to this email.
<br />
If you need assistance, feel free to contact our support team.
<br /><br />
Thank you for choosing us!
</p>
2026-04-02 21:27:09 +06:00
<hr />
<div
style="
text-align: center;
font-size: 12px;
color: #999999;
margin-top: 20px;
"
>
&copy; 2026 to {{year}} Quick Launch. All rights reserved.
</div>
2026-04-02 21:27:09 +06:00
</div>
</body>
2026-04-02 21:27:09 +06:00
</html>
2026-04-02 21:27:09 +06:00
`,
2026-04-12 22:47:56 +06:00
});
return info
2026-04-02 21:27:09 +06:00
};
export default sendMail;