【问题标题】:Attachment is not working properly in node-mailer?附件在节点邮件程序中无法正常工作?
【发布时间】:2013-06-16 22:19:13
【问题描述】:

您好,我正在使用节点邮件程序发送邮件。它可以在没有附件的情况下正常工作。但是每当我提供一些附件时,它都会将默认内容“数据”作为其内容。我应该如何避免这种情况..

我的节点邮件功能是这样的......

function sendMail(toMailId, subject, body) {
    for (var i = 0; i < 1; i++) {
        email.send({
            ssl: true,
            host: DbConfig.mailConfig.host,              
            port: DbConfig.mailConfig.port,             
            domain: DbConfig.mailConfig.domain,        
            to:  DbConfig.mailConfig.to,
            from: DbConfig.mailConfig.from,
            subject: subject,
            reply_to: DbConfig.mailConfig.reply_to,
            body: body,
            authentication: DbConfig.mailConfig.authentication, 
            username: DbConfig.mailConfig.username,            
            password: DbConfig.mailConfig.password,
             attachments: [  
        {   
            filename: "helloworld.txt",
            content : 'data'    
        }   
        ],
           debug: DbConfig.mailConfig.debug                 
        },
  function (err, result) {
      if (err) { console.log(err); }
  });
    }
}

我的问题是当我在收件箱中收到邮件后打开附件时,它只是在正文中显示数据。除此之外,它什么也不显示。当我删除内容时意味着它会引发错误..

我的 Json 将如下所示:

{ 
 "mongodbUrl":"mongodb://USERID:PWD@localhost:27017/DBNAME",
 "mailConfig" :{
             "to":"someone@gmail.com",
             "host": "smtp.gmail.com",            
             "port": 465,                    
             "domain": "[127.0.0.1]",           
             "from":"sender@gmail.com" ,
             "subject":"This is my mail subject,
              "reply_to": "sender@gmail.com",
              "authentication": "login",       
              "username": "sender@gmail.com",         
               "password": "pswd",   
               "debug": true      

}
}

当我发送 PDF 文件意味着它没有打开.. 当发送文本文件意味着它正在使用“内容数据”打开.. 如何处理这个?

【问题讨论】:

    标签: node.js pdf pdf-generation nodemailer


    【解决方案1】:

    我认为您使用的是Marak/node_mailer 而不是andris9/Nodemailer。第一个 repo 本身说它已弃用,并指向第二个,如您在其 github 页面中所见。

    项目弃用,取而代之的是 nodemailer

    您可以通过

    安装Nodemailer
    npm install nodemailer
    

    或来自github repo。并且暴露的邮件功能将是sendMail 而不是send

    您可以在此folder 中查看更多使用电子邮件附加文件的示例。

    【讨论】:

      猜你喜欢
      • 2013-05-09
      • 2017-11-08
      • 2013-11-09
      • 2017-06-25
      • 2014-01-09
      • 1970-01-01
      • 2021-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多