我构建了一个基本的node.js应用程序,用户可以在其中注册每周一次的电子邮件。
目前,当用户在我的网站上注册时,他们会收到验证电子邮件以确认其号码。
我现在想做的是,一旦用户确认了他们的电话号码,就会向我发送一封用户已注册该电子邮件的电子邮件。
有关于如何设置的简单方法/教程吗?
我是否为此创建了自定义webhook?这是我下面的.js文件:
var client = require('twilio')(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);
module.exports.sendMessage = function(phone, msg, callback) {
// console.log(client)
console.log(phone);
console.log(msg);
client.sms.messages.create({
to: phone,
from: '+1XXXXXXXXXX',
body: msg
}, function(error, message) {
// The HTTP request to Twilio will run asynchronously. This callback
// function will be called when a response is received from Twilio
// The "error" variable will contain error information, if any.
// If the request was successful, this value will be "falsy"
if (!error) {
// The second argument to the callback will contain the information
// sent back by Twilio for the request. In this case, it is the
// information about the text messsage you just sent:
console.log('Success! The SID for this SMS message is:');
console.log(message.sid);
console.log('Message sent on:');
console.log(message.dateCreated);
} else {
console.log('Oops! There was an error.');
}
callback(error);
});
};
答案 0 :(得分:0)
您可以使用Nodemailer让它向您发送通知。
https://github.com/nodemailer/nodemailer
var nodemailer = require('nodemailer');
// setup e-mail data with unicode symbols
var mailOptions = {
from: 'yourappsemail@gmail.com', // sender address
to: 'yourpersonalemail@gmail.com', // list of receivers
subject: 'Alert you have a new subscriber', // Subject line
text: phone+' - has signed up' // plaintext body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});