通过NodeJS发送带有附件的

通过NodeJS发送带有附件的

本文介绍了通过NodeJS发送带有附件的邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有最好的问候,
sdepold

解决方案

是的,这很简单,
我使用nodemailer: npm install nodemailer --save p>

  var mailer = require('nodemailer'); 
mailer.SMTP = {
host:'host.com',
port:587,
use_authentication:true,
user:'[email protected]' ,
pass:'xxxxxx'
};

然后阅读文件并发送电子邮件:

  fs.readFile(./ attachment.txt,function(err,data){

mailer.send_mail({
sender: '[email protected]',
to:'[email protected]',
subject:'Attachment!',
body:'mail content ...',
附件:[{'filename':'attachment.txt','content':data}]
}),function(err,success){
if(err){
/ /处理错误
}

}
});


Is there any library for NodeJS for sending mails with attachment?

With best regards,sdepold

解决方案

Yes, it is pretty simple,I use nodemailer: npm install nodemailer --save

var mailer = require('nodemailer');
mailer.SMTP = {
    host: 'host.com',
    port:587,
    use_authentication: true,
    user: '[email protected]',
    pass: 'xxxxxx'
};

Then read a file and send an email :

fs.readFile("./attachment.txt", function (err, data) {

    mailer.send_mail({
        sender: '[email protected]',
        to: '[email protected]',
        subject: 'Attachment!',
        body: 'mail content...',
        attachments: [{'filename': 'attachment.txt', 'content': data}]
    }), function(err, success) {
        if (err) {
            // Handle error
        }

    }
});

这篇关于通过NodeJS发送带有附件的邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 01:16