Simplify appointment email: HTML body, no PDF attachment (LibreOffice spawn unreliable from Node.js)
This commit is contained in:
parent
cef29c7f1f
commit
e8ef4589c9
2 changed files with 25 additions and 35 deletions
|
|
@ -82,7 +82,6 @@ export async function POST(req: NextRequest) {
|
|||
directorName: fullName || "Director",
|
||||
companyName: company_name || "the Company",
|
||||
signUrl,
|
||||
pdfPath,
|
||||
});
|
||||
|
||||
// 6. Update status to mail_sent
|
||||
|
|
@ -170,10 +169,8 @@ async function sendAppointmentEmail(opts: {
|
|||
directorName: string;
|
||||
companyName: string;
|
||||
signUrl: string;
|
||||
pdfPath: string;
|
||||
}) {
|
||||
const { to, directorName, companyName, signUrl, pdfPath } = opts;
|
||||
const hasPdf = pdfPath && pdfPath.length > 0;
|
||||
const { to, directorName, companyName, signUrl } = opts;
|
||||
|
||||
const subject = `[${directorName}] Acceptance letter as director for ${companyName}`;
|
||||
const body = `Good day ${directorName}
|
||||
|
|
@ -188,38 +185,34 @@ Regards`;
|
|||
|
||||
const boundary = "----YSTERBAARD" + Date.now();
|
||||
|
||||
let eml: string;
|
||||
if (hasPdf) {
|
||||
const pdfBuf = readFileSync(pdfPath);
|
||||
const pdfB64 = pdfBuf.toString("base64");
|
||||
eml = `To: ${to}\r
|
||||
// Send as HTML email (PDF generation via LibreOffice is unreliable when spawned from Node.js)
|
||||
const eml = `To: ${to}\r
|
||||
From: SJ@Dyfins.com\r
|
||||
Subject: ${subject}\r
|
||||
MIME-Version: 1.0\r
|
||||
Content-Type: multipart/mixed; boundary="${boundary}"\r
|
||||
Content-Type: text/html; charset="utf-8"\r
|
||||
\r
|
||||
--${boundary}\r
|
||||
Content-Type: text/plain; charset="utf-8"\r
|
||||
\r
|
||||
${body}\r
|
||||
--${boundary}\r
|
||||
Content-Type: application/pdf; name="appointment-letter.pdf"\r
|
||||
Content-Transfer-Encoding: base64\r
|
||||
Content-Disposition: attachment; filename="appointment-letter.pdf"\r
|
||||
\r
|
||||
${pdfB64}\r
|
||||
--${boundary}--\r
|
||||
<!DOCTYPE html><html><head><meta charset="utf-8"></head>
|
||||
<body style="font-family:Arial,sans-serif;font-size:14px;color:#222;max-width:600px;margin:40px auto;padding:0 20px;">
|
||||
<div style="background:#f8f9fa;border:1px solid #ddd;border-radius:8px;padding:24px;">
|
||||
<p>Good day <strong>${directorName}</strong>,</p>
|
||||
<p>Please find below the letter to accept your appointment as director for <strong>${companyName}</strong>.</p>
|
||||
<div style="background:#fff;border:1px solid #eee;border-radius:6px;padding:20px;margin:20px 0;">
|
||||
<h1 style="font-size:16px;text-align:center;margin:0 0 4px;">LETTER OF APPOINTMENT AS DIRECTOR</h1>
|
||||
<hr style="border:none;border-top:1px solid #333;margin:8px 0 16px;">
|
||||
<p>We are pleased to inform you that you have been appointed as a Director of <strong>${companyName}</strong>.</p>
|
||||
<p>Your appointment is subject to your formal acceptance in terms of section 70 of the Companies Act 71 of 2008.</p>
|
||||
<p><strong>To accept your appointment, please click the button below and draw your signature:</strong></p>
|
||||
<p style="text-align:center;margin:24px 0;">
|
||||
<a href="${signUrl}" style="display:inline-block;background:#0066cc;color:#fff;padding:12px 24px;border-radius:6px;text-decoration:none;font-size:14px;font-weight:bold;">
|
||||
Accept Appointment & Sign
|
||||
</a>
|
||||
</p>
|
||||
<p>Or copy this link into your browser:<br/><span style="color:#0066cc;font-size:12px;word-break:break-all;">${signUrl}</span></p>
|
||||
<p>Please note that until your acceptance is received, your appointment is not complete.</p>
|
||||
<p>Yours sincerely,<br/><strong>The Board of ${companyName}</strong></p>
|
||||
</div></div></body></html>\r
|
||||
`;
|
||||
} else {
|
||||
eml = `To: ${to}\r
|
||||
From: SJ@Dyfins.com\r
|
||||
Subject: ${subject}\r
|
||||
MIME-Version: 1.0\r
|
||||
Content-Type: text/plain; charset="utf-8"\r
|
||||
\r
|
||||
${body}\r
|
||||
`;
|
||||
}
|
||||
|
||||
const emlPath = `/tmp/appt-email-${Date.now()}.eml`;
|
||||
writeFileSync(emlPath, eml, "utf8");
|
||||
|
|
@ -240,8 +233,5 @@ ${body}\r
|
|||
if (err.trim()) console.error("himalaya stderr:", err.trim());
|
||||
} finally {
|
||||
unlinkSync(emlPath);
|
||||
if (pdfPath && pdfPath.length > 0) {
|
||||
try { unlinkSync(pdfPath); } catch { /* ok */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue