mirror of
https://github.com/wassname/talk.git
synced 2026-07-02 06:13:05 +08:00
mailer module v1
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = tab
|
||||
indent_style = space
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
"mongoose": "^4.6.5",
|
||||
"morgan": "^1.7.0",
|
||||
"nodemailer": "^2.6.4",
|
||||
"nodemailer-sendgrid-transport": "^0.2.0",
|
||||
"prompt": "^1.0.0",
|
||||
"uuid": "^2.0.3"
|
||||
},
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
const nodemailer = require('nodemailer');
|
||||
const sgTransport = require('nodemailer-sendgrid-transport');
|
||||
const options = {
|
||||
auth: {
|
||||
api_key: process.env.TALK_SENDGRID_APIKEY
|
||||
}
|
||||
};
|
||||
|
||||
const transporter = nodemailer.createTransport(sgTransport(options));
|
||||
|
||||
transporter.sendMail({
|
||||
from: 'support@mrdavis.com',
|
||||
to: 'riley.davis@gmail.com',
|
||||
subject: 'this is only a test',
|
||||
text: 'this is the body of the email maybe?',
|
||||
html: `<table>
|
||||
<thead>
|
||||
<tr><th>foo</th><th>bar</th><tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>riley</td><td>davis</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>`
|
||||
});
|
||||
|
||||
const mailer = {
|
||||
/**
|
||||
* sendSimple
|
||||
*
|
||||
* @param {Object} {from, to, subject, text = '', html = ''}
|
||||
* @returns
|
||||
*/
|
||||
sendSimple ({from, to, subject, text = '', html = ''}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!from) {
|
||||
reject('sendSimple requires a from address');
|
||||
}
|
||||
if (!to) {
|
||||
reject('sendSimple requires a comma-separated list of "to" addresses');
|
||||
}
|
||||
if (!subject) {
|
||||
reject('sendSimple requires a subject for the email');
|
||||
}
|
||||
|
||||
return resolve(transporter.sendMail({from, to, subject, text, html}));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = mailer;
|
||||
Reference in New Issue
Block a user