1.0.2 • Published 7 years ago

egg-email v1.0.2

Weekly downloads
116
License
MIT
Repository
github
Last release
7 years ago

egg-email

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Email 插件是为 egg 提供 email 邮件服务的功能

依赖的 egg 版本

egg-email 版本egg 1.x
1.x😁
0.x

安装

$ npm install egg-email --save

开启插件

// config/plugin.js
exports.email = {
  enable: true,
  package: 'egg-email',
};

配置

通过config/plugins.js 来启动 Email 插件

exports.email = {
    enable: true,
    package: 'egg-email',
}

config/config.${env}.js配置各个环境的邮件服务连接信息;

单数据源

exports.email = {
    client: {
       host: 'smtp.qq.com',
       secureConnection: true,
       port: 465,
       auth: {
           user: 'test_user',
           pass: 'test_pass'
       }
    }
}

使用方法:

const mailOptions = {
    from: 'qoderplus@gmail.com',
    to: 'test_user@qq.com',
    subject: 'hello world',
    html: `<a href = 'link'>点击链接进行验证</a>`
};

app.email.sendMail(mailOptions, (error, response) => {
    if (error) {
        console.log('error:', error);
    } else {
        console.log('email sent: ' + response.message);
    }
    app.email.close();
});

多数据源

exports.email = {
  clients: {
      mail1: {
         host: 'smtp.qq.com',
         secureConnection: true,
         port: 465,
         auth: {
             user: 'test_user',
             pass: 'test_pass'
         }, 
      },
  },
  //所有的邮件服务配置默认值
  default: {
      
  }
};

使用方法:

const client1 = app.email.get('mail1');
//...
const client2 = app.email.get('mail2');

扩展

app.js

app.email

如果开启了 config.email.app = true,则会在 app 上注入 nodemailer 客户端 的 Singleton 单例

agent.js

agent.mysql

如果开启了 config.email.agent = true,则会在 agent 上注入 nodemailer 客户端 的 Singleton 单例

详细配置

请到 config/config.default.js 查看详细配置项说明。

提问交流

请到 egg issues 异步交流。

License

MIT