think-mailer
v1.0.2
Published
Mailer adaper
Downloads
2
Readme
think-mailer
Thinkjs mailer adapter
Development based on nodemailer
Install
yarn add think-mailer --save
#npm install think-mailer --save
#cnpm install think-mailer --save
Config
ThinkJSProjectRoot/src/config/adapter.js
exports.mailer = {
type: 'mailer',
mailer: {
host: 'smtp.xxx.com',
port: 465,
secure: true,
auth: {
user: '[email protected]', // your account
pass: 'JfoBrEMBYkzhvzRB' // authorization code, not the email password
},
tls: {
rejectUnauthorized: false
}
}
};
ThinkJSProjectRoot/src/config/extend.js
const view = require('think-view');
const cache = require('think-cache');
const session = require('think-session');
const mongo = require('think-mongo');
const email = require('think-mailer');
module.exports = [view, mongo(think.app), cache, session, email(think.app)];
Send Mail
ThinkJSProjectRoot/src/controller/xxx.js
const Base = require('./base.js');
module.exports = class extends Base {
indexAction() {
const ctx = this
const mailer = ctx.mailer()
return mailer.send({
from: '[email protected]',
to: '[email protected]',
subject: 'Email Tile',
html: '<p>Email content</p>'
})
.then(async function(res) {
return ctx.success({
msg: 'Email Sent.'
})
})
.catch(function(err) {
console.log(err)
return ctx.fail(1000, 'Email send failed.')
})
}
};