50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import nodemailer from 'nodemailer';
|
|
|
|
const config = useRuntimeConfig();
|
|
const [domain, selector, dkim] = config.mail.dkim.split(":");
|
|
|
|
const transport = nodemailer.createTransport({
|
|
pool: true,
|
|
host: config.mail.host,
|
|
port: config.mail.port,
|
|
secure: false,
|
|
auth: {
|
|
user: config.mail.user,
|
|
pass: config.mail.passwd,
|
|
},
|
|
requireTLS: true,
|
|
dkim: {
|
|
domainName: domain,
|
|
keySelector: selector,
|
|
privateKey: dkim,
|
|
},
|
|
});
|
|
|
|
export default defineTask({
|
|
meta: {
|
|
name: 'mail',
|
|
description: 'Send email',
|
|
},
|
|
async run(e) {
|
|
try {
|
|
const payload: { to: string[], message: string, subject: string } = e.payload;
|
|
const status = await transport.sendMail({
|
|
from: 'Message automatique d[any] <no-reply@peaceultime.com>',
|
|
to: payload.to,
|
|
text: payload.message,
|
|
subject: payload.subject,
|
|
});
|
|
|
|
if(status.rejected.length > 0)
|
|
{
|
|
return { result: false, error: status.response, details: status.rejectedErrors };
|
|
}
|
|
|
|
return { result: true };
|
|
}
|
|
catch(e)
|
|
{
|
|
return { result: false, error: e };
|
|
}
|
|
},
|
|
}) |