support mail
parent
8d2b66913c
commit
d161f259ff
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"command": "npm start",
|
||||||
|
"name": "Run npm start",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "node-terminal"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,26 @@
|
|||||||
|
const { sendEmail } = require('../../../utils/mail');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
inputs: {
|
||||||
|
to: {
|
||||||
|
type: 'json',
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
subject: {
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
type: 'string',
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
cc: {
|
||||||
|
type: 'json',
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
async fn({ to = [], subject = '', text = '', cc = [] }) {
|
||||||
|
const mailResult = await sendEmail({ to, subject, text, cc });
|
||||||
|
return mailResult;
|
||||||
|
},
|
||||||
|
};
|
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,36 @@
|
|||||||
|
const nodemailer = require('nodemailer');
|
||||||
|
|
||||||
|
const mailerConfig = {
|
||||||
|
host: sails.config.custom.mailConnectorHost,
|
||||||
|
port: sails.config.custom.mailConnectorPort,
|
||||||
|
};
|
||||||
|
if (sails.config.custom.mailConnectorUser) {
|
||||||
|
Object.assign(mailerConfig, {
|
||||||
|
auth: {
|
||||||
|
user: sails.config.custom.mailConnectorUser,
|
||||||
|
pass: sails.config.custom.mailConnectorPass,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const transport = nodemailer.createTransport(mailerConfig);
|
||||||
|
|
||||||
|
const sendEmail = async ({ to, subject, text, cc }) => {
|
||||||
|
try {
|
||||||
|
await transport.sendMail({
|
||||||
|
from: sails.config.custom.mailConnectorEmail,
|
||||||
|
to,
|
||||||
|
cc,
|
||||||
|
subject,
|
||||||
|
html: text,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
sails.log(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const sendUserEmails = async ({ ids, subject, text, cc }) => {
|
||||||
|
const users = await sails.helpers.users.getMany(ids);
|
||||||
|
return sendEmail({ to: users.map((u) => u.email), subject, text, cc });
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = { sendEmail, sendUserEmails };
|
||||||
Loading…
Reference in New Issue