当前位置:  开发笔记 > 前端 > 正文

使用loopback email数据源发送带附件的电子邮件

如何解决《使用loopbackemail数据源发送带附件的电子邮件》经验,为你挑选了1个好方法。



1> Farid Nouri ..:

来自文档:

Nodemailer:在哪里查找文档

电子邮件连接器本质上是节点编辑器库的LoopBack集成接口.此页面给出了一个用法示例; 有关配置选项的完整文档,请参阅nodemailer文档.

这是节点制作者记录附件的地方.

以下是环回上下文中不同类型附件的示例:

app.models.Email.send({
  to: 'example@example.com',
  from: 'no-reply@example.com',
  subject: 'Email Subject',
  html: 'Hello',
  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!'
    }
  ],
}, err => {
  if (err) {
    throw err;
  }
});

推荐阅读
linjiabin43
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有