NodeJS
を使用してフォーム情報を API に送信するお問い合わせフォームがサイトにありますNodemailer
。
私のコードは次のようになります。
var mail = {
from: data.inputName + " <" + data.inputEmail + ">",
to: 'info@mywebsite.com',
subject: "Inquiry",
text: messageText
}
var smtpTransport = mailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "info@mywebsite.com",
pass: "password12345678"
}
});
smtpTransport.sendMail(mail, function(error, response){
if(error){
console.log(error);
if(res){
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.send('error');
}
}else{
console.log("Message sent: " + response.message);
if(res){
console.log("There was res!");
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.send('success');
}else{
console.log("There wasn't res!");
}
}
smtpTransport.close();
});
ここからメールを受信すると、次のようになります。
from: User's Inputted Name <info@mywebsite.com> <--- this is bad
to: info@mywebsite.com <--- this is correct
date: 10 April 2014 18:06
subject: Inquiry
from
フィールドをユーザーのものにするにはどうすればよいdata.inputEmail
ですか? info@mywebsite.com
ユーザー名とパスワードを使用して SMTPTransport にログインしたためだと思いますが、これを回避する方法がまったくわかりません。
何か案は?