我遇到与angular和nodejs(express)有关的问题。
因此,我尝试从角度的一种形式发送电子邮件,然后使用post方法传递值。问题是信息未到达主机上的节点服务器。我用邮递员测试了端点,并且工作正常(禁用了ssl),但是尝试从网站发送时却什么也没收到,只有ERR_CONN_TIMEOUT错误。
我正在使用a2hosting共享托管,并且我将.htaccess编辑为如下所示:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteRule ^$ http://127.0.0.1:30001/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ https://example.com:30001/$1 [P,L]
RewriteRule . /index.html [L]
</IfModule>
角度端点如下:
sendEmail(data){
//let url = "http:/localhost:30001/sendmail";
let url = "https://example.com:30001/sendmail";
let headers1 = new Headers({'Content-Type': 'application/json'});
console.log(JSON.stringify(data));
return this.http.post(url, JSON.stringify(data), {headers: headers1});
}
对于使用emailjs的节点部分:
app.post("/sendmail", (req, res) => {
var userEmail = req.body.email;
var name = req.body.name;
var subject = req.body.subject;
var message = req.body.message;
console.log(message);
var server = email.server.connect({
user: "username@somemail.com",
password:"password",
host: "one.smtp.two",
ssl: true, //or false
port: 465 //or 25 without ssl
});
// send the message and get a callback with an error or details of the message that was sent
server.send({
text: message,
from: "from@email.com",
to: "destination@mail.com",
cc: null,
subject: subject
}, function(err, message) {
if(err){
console.log(err || message);
}
else{
return res.json({success: true, msg: "success"});
}
});
});
我的主机运行centos7,并具有apache服务器。
我不确定我的设置是否错误或有人可以将我指向此处。我尝试将.htaccess更改为http和https。该网站仅在本地发送电子邮件,并且禁用了ssl(以及邮递员)。请帮我这个家伙!谢谢!