2013-02-03 40 views

回答

6

Nodemailer是一種流行的,穩定的,靈活的解決方案:

全部使用看起來像這樣(最高位是剛剛設置 - 讓你不僅會每個應用程序必須這樣做):

var nodemailer = require("nodemailer"); 

// create reusable transport method (opens pool of SMTP connections) 
var smtpTransport = nodemailer.createTransport("SMTP",{ 
    service: "Gmail", 
    auth: { 
     user: "[email protected]", 
     pass: "userpass" 
    } 
}); 

// setup e-mail data with unicode symbols 
var mailOptions = { 
    from: "Fred Foo ✔ <[email protected]>", // sender address 
    to: "[email protected], [email protected]", // list of receivers 
    subject: "Hello ✔", // Subject line 
    text: "Hello world ✔", // plaintext body 
    html: "<b>Hello world ✔</b>" // html body 
} 

// send mail with defined transport object 
smtpTransport.sendMail(mailOptions, function(error, response){ 
    if(error){ 
     console.log(error); 
    }else{ 
     console.log("Message sent: " + response.message); 
    } 

    // if you don't want to use this transport object anymore, uncomment following line 
    //smtpTransport.close(); // shut down the connection pool, no more messages 
}); 
+0

感謝這個完美的作品 - 剛剛試了一下! –

+5

晚會到了這裏。使用nodemailer你需要一個認證。 PHP的郵件()方法,你不需要一個權威性的權利?它只會發送給您在腳本中指定的電子郵件。至少這是我的經驗。有沒有這樣的節點,不需要身份驗證發送到Gmail ...我可以從一個PHP腳本發送電子郵件到我的gmail沒有在驗證中指定的密碼,但在nodemailer我必須有驗證那裏 – Chipe

+0

使用Nodemailer也是可能的。我編輯了這個答案以包含直接鏈接。 https://nodemailer.com/transports/sendmail/ – Neon

相關問題