Node.js 如何使用nodemail将URL图像附加到电子邮件?

Node.js 如何使用nodemail将URL图像附加到电子邮件?,node.js,request,nodemailer,Node.js,Request,Nodemailer,我正在尝试通过url链接将图像附加到我正在发送的电子邮件。这是我的密码 var nodemailer = require("nodemailer"); var fs = require("fs"); var request = require("request"); exports.index = function index(req, res){ var transporter = nodemailer.createTransport("SMTP", { servic

我正在尝试通过url链接将图像附加到我正在发送的电子邮件。这是我的密码

var nodemailer = require("nodemailer");
var fs = require("fs");
var request = require("request");

exports.index = function index(req, res){
    var transporter = nodemailer.createTransport("SMTP", {
        service: 'yahoo',
        auth: {
            user: '__@yahoo.co.uk',
            pass: '_'
        }
    });
    var attachedfile;

        request.get('http://i.imgur.com/iIAS1wE.jpg', function (error, response, body) {
            if (!error && response.statusCode == 200) {
                attachedfile = body;
            }
        });
        var options = {
            from: '__@yahoo.co.uk',
            to: '__@yahoo.co.uk',
            subject: 'hello',
            text: 'hello! See attached files',
            attachments: [
            {filename: 'starwars.jpg', contents: attachedfile }]
        }
        transporter.sendMail(options , function(err, response){
        if(err){
            console.log(err);
        } else {
            console.log('Message sent: ' + response.message);
        }
        transporter.close();
        });
    res.render('email/index');
}
但是当我查看电子邮件时没有图像…我在这里做错了什么?
谢谢

您不需要手动获取文件(以防您不发送批量电子邮件), nodemailer可以为您做到这一点:

 attachments: [
            {path: 'http://i.imgur.com/iIAS1wE.jpg'}]

您不需要手动获取文件(以防您不发送批量电子邮件), nodemailer可以为您做到这一点:

 attachments: [
            {path: 'http://i.imgur.com/iIAS1wE.jpg'}]

NodeEmailer自动从提供的URL获取和附加文件。这是一个例子


NodeEmailer自动从提供的URL获取和附加文件。这是一个例子


嗯,我试过了,但是图像文件没有附在发送的电子邮件上。我终于找到了,是“文件路径”,不是“文件”。嗯,我试过了,但是图像文件没有附在发送的电子邮件上。我终于找到了,是“文件路径”,不是“文件”。