mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-21 01:46:28 +08:00
Hello Typescript!
This commit is contained in:
1 parent
c9b6412527
commit
ba03d7a7bf
98 files changed
+3186
-2616
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import nodemailer from 'nodemailer';
|
||||
|
||||
const { SendMailError } = require('../error');
|
||||
|
||||
/**
|
||||
* @param {string} to
|
||||
* @param {string} subject
|
||||
* @param {string} text
|
||||
* @param {string} html
|
||||
*/
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export async function sendMail(to: string, subject: string, text: string, html: string) {
|
||||
let t: unknown;
|
||||
try {
|
||||
const { system } = global.Hydro.model;
|
||||
const [host, port, secure, user, pass, from] = await Promise.all([
|
||||
system.get('smtp.host'),
|
||||
system.get('smtp.port'),
|
||||
system.get('smtp.secure'),
|
||||
system.get('smtp.user'),
|
||||
system.get('smtp.pass'),
|
||||
system.get('smtp.from'),
|
||||
]);
|
||||
const transporter = nodemailer.createTransport({
|
||||
host, port, secure, auth: { user, pass },
|
||||
});
|
||||
t = await new Promise((resolve, reject) => {
|
||||
transporter.sendMail({
|
||||
from,
|
||||
to,
|
||||
subject,
|
||||
text,
|
||||
html,
|
||||
}, (err, info) => {
|
||||
if (err) reject(err);
|
||||
else resolve(info);
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
throw new SendMailError(to);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
global.Hydro.lib.mail = {
|
||||
sendMail,
|
||||
};
|
||||
Reference in new issue
Block a user