简体   繁体   English

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

[英]how to send email using attachments in nodejs?

This program works perfectly, but attachments files are not sent. 该程序可以完美运行,但是不会发送附件文件。 Can anyone give me the correct solution?. 谁能给我正确的解决方案? Thanks in advance. 提前致谢。

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");
    });

attachments should be lowercased. attachments应小写。 You're using Attachments . 您正在使用Attachments

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM