2017-08-05 59 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表中該代碼發送郵件通知 –

相關問題