附件在节点邮件中无法正常工作?

时间:2013-06-20 07:01:13

标签: node.js pdf pdf-generation nodemailer

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

我的节点邮件功能看起来像这样......

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文件意味着它没有打开..当发送文本文件意味着它打开了'内容数据'..如何处理?

1 个答案:

答案 0 :(得分:0)

我认为您使用Marak/node_mailer代替andris9/Nodemailer。第一个repo本身表示已弃用并指向第二个,正如您在其github页面中看到的那样。

  

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

您可以通过

安装Nodemailer
npm install nodemailer

或来自github repo。并且公开的邮件程序功能将是sendMail而不是send

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