如何使用nodejs中的附件发送电子邮件?

时间:2017-09-07 16:11:11

标签: node.js email-attachments nodemailer

此程序运行正常,但不会发送附件文件。任何人都可以给我正确的解决方案吗?提前谢谢。

var nodemailer = require('nodemailer');
var fs=require("fs");
var smtpTransport = require('nodemailer-smtp-transport');
var transporter = nodemailer.createTransport(smtpTransport({
    service: 'Gmail',
    host: 'smtp.gmail.com',
    port: 465,
    auth: {
        user: 'sampleprogrammers@gmail.com',
        pass: 'xvbthhegebeb.'
    }
}));

    transporter.sendMail({
        from: "sampleprogrammers@gmail.com",
        subject:" hello ji " ,
        text: "I would like to write dialogue",
        Attachments:[
            {
                'filename':'link.txt',
                'path': 'E:/STUDIES/CORE SUBJECTS/link.txt'
            }
        ],
        to: "vikirockz456@gmail.com"
    }, function(error, info) {
        if (error) {
            return console.log(error);
        }
        console.log('Message %s sent: %s', info.messageId, info.response);
        console.log("Mail sent successfully");
    });

1 个答案:

答案 0 :(得分:0)

attachments应该是小写的。您正在使用Attachments

参考:https://nodemailer.com/message/attachments/