我在这里使用 nodemailer 模块:https ://github.com/andris9/Nodemailer以便从 web 应用程序自动发送电子邮件。使用 Firefox 在 PC 浏览器上对其进行了测试,一切似乎都运行良好。但是,当我使用 iphone safari 来使用该应用程序时,它似乎没有发送电子邮件。我一直在为此挠头,如果有人知道这是什么原因,我将不胜感激!注意我正在使用 gmail 服务,但我已经设置了我的 gmail,以便它将消息作为另一个地址发送(在本例中为 xyz@abc.com)。我的代码如下:
电子邮件模块:
var nodemailer = require("nodemailer");
function sendEmail(firstname, email){
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "user@gmail.com",
pass: "mypassword"
}
});
smtpTransport.sendMail({
from: "Sender <xyz@abc.com>",
to: email,
subject: "blahblah",
text: "blah blah blah",
}, function(error, response){
if(error){
console.log(error);
} else{
console.log("Success!");
}
});
}
exports.sendEmail = sendEmail;
应用模块:
var express = require("express");
var fs = require("fs");
var clientEmail = require("./clientEmail.js");
var profileEmail = require("./profileEmail.js");
var app = express();
app.use('/css', express.static(__dirname + '/css'));
app.use('/img', express.static(__dirname + '/img'));
app.use('/javascript', express.static(__dirname + '/javascript'));
app.use(express.bodyParser());
var buf = fs.readFileSync("html/index.html");
var index = buf.toString();
app.get('/', function(request, response) {
response.send(index);
});
app.post('/', function(request, response){
var email = request.body.email;
var name = request.body.name;
var firstname = request.body.firstname;
clientEmail.sendEmail(firstname,email);
response.redirect('/');
});
var port = process.env.PORT || 5000;
app.listen(port, function() {
console.log("Listening on " + port);
});