2017-08-05 60 views
-1

这是我的代码。当它在邮差中运行时,它显示错误就像无法获取方法。使用nodejs发送邮件的模板设计

var sendTempMail = function (req,res) 
{ 
    const nodemailer = require('nodemailer'); 

    let transporter = nodemailer.createTransport({ 
     host: 'smtp.gmail.com', 
     auth: { 
      user: '[email protected]', 
      pass: '[email protected]' 
     } 
    }); 

    let mailOptions = { 
     from: '[email protected]', 
     to: '[email protected]','[email protected]',[email protected],//here to:receiver not accept more than one 
     subject: 'mail notification Test', 
     text: 'Hello !!!!!!!!!everything works fine' 
     html:<h1>Notification mail</h1> 

    <head> 

    <style> 

    table, th, td { 
     border: 1px solid black; 
     border-collapse: collapse; 
    } 

    th, td { 
     padding: 10px; 
     text-align: left; 
    } 

    </style> 

    </head> 

    <body> 

      <table style="width:100%"> 

     <tr> 

     <th>Firstname</th> 

     <th>Lastname</th> 

     <th>Age</th> 

     </tr> 

     <tr> 

     <td>Jill</td> 

     <td>Smith</td> 

     <td>50</td> 

     </tr> 

     <tr> 

     <td>Eve</td> 

     <td>Jackson</td> 

     <td>94</td> 

     </tr> 

     <tr> 

     <td>John</td> 

     <td>Doe</td> 

     <td>80</td> 

     </tr> 

    </table> 



    </body> 

    }; 

    transporter.sendMail(mailOptions, (error, info) => { 
     if (error) { 
      return console.log("mail not sent" +error.message); 
     } 

     console.log('success'); 
    }); 
}; 

module.exports = { 
    newTemplate :newTemplate, 
    sendTempMail : sendTempMail 
}; 
+0

请复制并粘贴确切的错误信息到这个问题。 – JJJ

回答

0

请粘贴您的错误信息与问题。不过,我可以看到一个错误,即HTML参数将所有原始html粘贴在那里。它应该是字符串格式。

请检查行代码中没有44以下链接 https://github.com/nodemailer/nodemailer/blob/master/examples/full.js

+0

当我运行此代码时,我得到不能发布postman.how中的此方法错误我将编写代码发送电子邮件html模板使用nodejs –

+0

邮政的尝试呼叫的路由URL是什么?它是否在您的应用程序路线中定义?如果邮递员无法找到它,那就意味着要么在邮递员中指定它是错误的,要么在应用程序本身中是错误的。请确认。 –

+0

如何设置HTML表中该代码发送邮件通知 –

相关问题