0

我构建了一个基本的 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);
    });

};
4

1 回答 1

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);

});
于 2016-01-07T13:56:24.330 回答