-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.ts
36 lines (32 loc) · 842 Bytes
/
mail.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import MailComposer from "nodemailer/lib/mail-composer";
import { Attachment } from "nodemailer/lib/mailer";
export const makeBody = ({from, to, body, subject, attachments}: {
from: string;
to: string;
body: string;
subject: string;
attachments?: Attachment[];
}) => {
let mail = new MailComposer({
to: to,
from: from,
html: body,
subject: subject,
attachments,
textEncoding: "base64",
});
// Compiles and encodes the mail.
return new Promise<string>((resolve, reject) => {
mail.compile().build((err, msg) => {
if (err){
return reject(err);
}
const encodedMessage = Buffer.from(msg)
.toString('base64')
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=+$/, '');
return resolve(encodedMessage);
});
})
}