Node.js Send Mail
Node.js做送Mail的動作相當簡單,下面是步驟,給大家參考: 1. 安裝mail套件 simonsuteki-MacBook-Pro:NodeJSWS simonsu$ sudo npm install mail Password: mail@0.2.3 ../../node_modules/mail └── reparse@0.1.2 2. 編寫程式:sendMail.js (紅色部份修改為自己的信箱與密碼,綠色部份一需求修改) var sys = require('sys'), mail = require('mail').Mail({ host: ' smtp.gmail.com ', port: 587, username: ' me@gmail.com ', password: ' **password** ' }); mail.message({ from: ' sender@example.net ', to: [' recipient@somewhere.org '], subject: 'Hello from Node.JS' }) . body('Node speaks SMTP!') .send(function(err) { if (err) throw err; sys.debug('Sent!'); }); 3. 執行寄送: simonsuteki-MacBook-Pro:NodeJSWS simonsu$ node sendMail.js DEBUG: Sent!