GithubHelp home page GithubHelp logo

bcore.email's Introduction

bcore.email

bcore微服务---邮件发送

  1. 基于bcore组件
  2. 依赖nodemailer
  3. 支持文本传输
  4. 支持附件传输
  5. 支持html内容传输
  6. 支持模板引擎编译后传输
  7. 支持Markdown文件传输

Options

  • debug: [Boolean] �是否开启调试 (Default:false)
  • logger: [Boolean] 是否开启日志 (Default:false)
  • from: [String] 发送方邮箱地址
  • auth: [Object-Hash] 发送方账户信息
  • host: [String] 邮件服务器主机名 (Default:smtp.126.com)
  • port: [Number] 发送端口(Default:465)
  • secure: [Boolean] �内容开启传输开关(Default:true)
  • pool: [Boolean] 是否使用邮件发送池(Default:false)

Method

sendPlain(subject,reciever,text,attachments):发送文本

  • subject: [String] 邮件主题
  • reciever: [String|Object] 邮件接收方
  • text: [String] 邮件正文(纯文本)
  • attachments:[Array] 邮件附件 Optional

sendHtml(subject,reciever,html,attachments):发送Html

  • subject: [String] 邮件主题
  • reciever: [String|Object] 邮件接收方
  • html: [String] 邮件正文(html字符串)
  • attachments:[Array] 邮件附件 Optional

sendTplHtml(subject,reciever,tplFile,tplContext,attachments):发送html模板

  • subject: [String] 邮件主题
  • reciever: [String|Object] 邮件接收方
  • fileUrl: [String] 邮件模板文件地址
  • tplContext:[Object] 邮件模板填充的上下文
  • attachments:[Array] 邮件附件 Optional

Note:

  1. attachments的传入格式如下:
[
    {   // utf-8 string as an attachment
        filename: 'text1.txt',
        content: 'hello world!'
    },
    {   // binary buffer as an attachment
        filename: 'text2.txt',
        content: new Buffer('hello world!','utf-8')
    },
    {   // file on disk as an attachment
        filename: 'text3.txt',
        path: '/path/to/file.txt' // stream this file
    },
    {   // filename and content type is derived from path
        path: '/path/to/file.txt'
    },
    {   // stream as an attachment
        filename: 'text4.txt',
        content: fs.createReadStream('file.txt')
    },
    {   // define custom content type for the attachment
        filename: 'text.bin',
        content: 'hello world!',
        contentType: 'text/plain'
    },
    {   // use URL as an attachment
        filename: 'license.txt',
        path: 'https://raw.github.com/nodemailer/nodemailer/master/LICENSE'
    },
    {   // encoded string as an attachment
        filename: 'text1.txt',
        content: 'aGVsbG8gd29ybGQh',
        encoding: 'base64'
    },
    {   // data uri as an attachment
        path: 'data:text/plain;base64,aGVsbG8gd29ybGQ='
    },
    {
        // use pregenerated MIME node
        raw: 'Content-Type: text/plain\r\n' +
                'Content-Disposition: attachment;\r\n' +
                '\r\n' +
                'Hello world!'
    }
]
  1. reciever 的格式有两种

只有接收人的情况:

 reciever: '[email protected]'

存在抄送人、密送人

    "reciever":{
        "to":"接收人邮箱地址",
        "cc":"抄送人邮箱地址",
        "bcc":"密送人邮箱地址"
    }

支持的模板引擎

利用文件后缀名判别�使用哪个模板引擎

  1. ejs: .ejs
  2. hbs: .hbs
  3. nunjucks: .njk | .html
  4. pug: .jade | .pug
  5. dot: .dot
  6. artTemplate: .art

Markdown Transport

在组件内部被归纳到了模板引擎一类执行处理,对应如下:

  1. Markdown: .md | .markdown

Test

目前只有简单测试,还没有依托在mochashould基础上的BDD测试

npm run test

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.