繁体   English   中英

通过mailgun发送电子邮件

[英]sending email through mailgun

我正在尝试使用nodejs express和mailgun-js将mailgun联系表单添加到我的网站。 但不知怎的,我无法让它发挥作用。 我的api密钥和域名很好,因为我在mailgun-js的官方github页面上使用示例代码测试它们。 所以我想知道以下代码是否有任何问题。 (路由和其他一切工作完美)

./models/mailer.js

            var api_key = 'xxxxxxx';
            var domain = 'xxxxxxxx';

            var Mailgun = require('mailgun-js');

            exports.sendOne = function (locals,callback) {

                console.log(locals);
                var mailgun = new Mailgun({apiKey: api_key,domain:domain});

                var data = {
              from: 'xxxxxx',
              to: 'myemail@hotmail.com',
              subject: 'Hello World',
              text: 'Testing some Mailgun awesomness!'
            };

                mailgun.message().send(data,function (err,body) {
                        if(err) return callback(err);
                        console.log('message sent');
                        callback(null,body);
                });
            };

./controllers/contactCtrl.js

    var mailer = require('../models/mailer');

    exports.contact = function (req,res,next) {
        res.render('contact');
    };


    exports.receiveMessage = function (req,res,next) {

            mailer.sendOne(req.body,function (err,body) {
                if(err) return next(err);
                console.log(body);
                res.send({message:'Your message has been successfully sent'});
            });

    };

非常感谢 :)

mailgun.message()

你错过了一个“s”。 它应该是mailgun.messages()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM