think-mailer

1.0.2 • Public • Published

think-mailer

npm Build Status Coverage Status NPM version Downloads

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: 'xxx@xxx.com', // 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: 'xxx@xxx.com',
      to: 'xxx@xxx.com',
      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.')
    })
  }
};

Dependencies (3)

Dev Dependencies (9)

Package Sidebar

Install

npm i think-mailer

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

131 kB

Total Files

8

Last publish

Collaborators

  • mlinquan