2016-06-29 5 views
1

(更新)こんにちはすべて私はNodejsを使用してメールに送信された友人を招待したい。主にサーバー側userpassを使用できますか?メールはまた、私は多くの方法を試してみました、その後送られたが、いずれかの解決策を知っていれば解を得ることができないことができない私を助けてください..... myplunkerどのように友人に招待メールに送信?

HTML: -

<div id="container"> 
<center> 
<input id="to" type="text" placeholder="Enter E-mail ID" /><br><br> 
<input id="subject" type="text" placeholder="Write Subject" /><br><br> 
<textarea id="content" cols="40" rows="5" placeholder="Message"></textarea><br><br> 
<button id="send_email">Send Email</button> 
</center> 
<span id="message"></span> 
</div> 

サーバー: -

var smtpTransport = nodemailer.createTransport("SMTP",{ 
    service: "Gmail", 
    use_authentication: true, 
    auth: { 
     user: "[email protected]", 
     pass: "password" 
    } 
}); 


app.get('/',function(req,res){ 
    res.sendfile('index.html'); 
}); 
app.get('/send',function(req,res){ 
    var mailOptions={ 
     to : req.query.to, 
     subject : req.query.subject, 
     text : req.query.text 
    } 
    console.log(mailOptions); 
    smtpTransport.sendMail(mailOptions, function(error, response){ 
    if(error){ 
      console.log(error); 
     res.end("error"); 
    }else{ 
      console.log("Message sent: " + response.message); 
     res.end("sent"); 
     } 
}); 
}); 
+0

メールを送信するには、サーバーの一部が必要です – Alexan

+0

私はangularjsを初めて使用しています。サーバの部分の解決策があれば教えてください。 –

+0

おそらく最も簡単な方法はPHPで送信することです。 [ここ](http://php.net/manual/es/function.mail.php)と[ここ](http://www.w3schools.com/php/func_mail_mail.asp)で確認してください。 –

答えて

0

次の手順は、あなたを助けることがあります。

メールが送信されていることをテストするには、サーバーのスクリプトの先頭

var express=require("express"); var app=express()を追加し、サーバー スクリプトの先頭

var nodemailer=require("nodemailer")の追加は、(あなたのapp.getにあるものを移動しますこのようになります)関数の外)スクリプトを「/送信」と今の(他のすべてのコメント:

var nodemailer=require("nodemailer"); 
var express=requre("express"); 
var app=express(); 
var smtpTransport = nodemailer.createTransport("SMTP",{ 
    service: "Gmail", 
    use_authentication: true, 
    auth: { 
     user: "[email protected]", 
     pass: "PASS" 
    } 
}); 

var mailOptions={ 
    to : "[email protected]", 
    subject :"SUBJECT", 
    text : "MESSAGE" 
} 


console.log(mailOptions); 
smtpTransport.sendMail(mailOptions, function(error, response){ 
if(error){ 
     console.log(error); 

}else{ 
     console.log("Message sent: " + response.message); 

    } 
}); 

/* 
app.get('/',function(req,res){ 
    res.sendfile('index.html'); 
}); 
app.get('/send',function(req,res){ 
    var mailOptions={ 
     to : req.query.to, 
     subject : req.query.subject, 
     text : req.query.text 
    } 
    console.log(mailOptions); 
    smtpTransport.sendMail(mailOptions, function(error, response){ 
    if(error){ 
      console.log(error); 
     res.end("error"); 
    }else{ 
      console.log("Message sent: " + response.message); 
     res.end("sent"); 
     } 
}); 
});*/ 

は、あなたが、これはあなたが電子メールを送信しようとしている電子メールのためにオンになっていることを確認します:How to downgrade this node.js module to specific version and prevent automatic upgrade later?

:nodemailerのバージョンが正しいことを確認してくださいhttps://www.google.com/settings/security/lesssecureapps

、それはあなたが持っているセットアップに0.71vする必要がありますnode fileName.jsサーバスクリプトを実行します(ヒントスタックをコピーしてください。)

すべての機能がアンコメントされていれば、app.getの外にあるmailOptionsとsmtpTransportが削除されます。すべてが今すぐ動作するはずです...

幸運には、これ以上問題がある場合はお手伝いします。

関連する問題