无法使用Sails.js和node-machine mailgun发送电子邮件

时间:2016-01-26 07:48:13

标签: javascript jquery node.js sails.js mailgun

我用sails创建了一个名为JoinUs的API。我想要的是在创建新注册表之前/之后发送电子邮件。 ( joinus / create 与蓝图)

我正在使用节点机器代码发送带有mailgun的电子邮件。但是,当我在JoinUs Controller(动作创建)中编写此代码时,它似乎无法正常工作。我有正确的mailgun凭据。

有什么想法吗?

/**
 * JoinUsController
 *
 * @description :: Server-side logic for managing joinuses
 * @help        :: See http://sailsjs.org/#!/documentation/concepts/Controllers
 */

module.exports = {

    create: function (res, req){
        var Mailgun = require('machinepack-mailgun');

        // Send an html email.
        Mailgun.sendHtmlEmail({
            apiKey: 'key-Xxxxxxxxxxxx',
            domain: 'domain.com',
            toEmail: 'dev@gmail.com',
            toName: 'DEV',
            subject: 'Welcome!',
            textMessage: 'Jane,\nThanks for joining our community. If you have any questions, please don\'t hesitate to send them our way. Feel free to reply to this email directly.\n\nSincerely,\nThe Management',
            htmlMessage: 'Jane,\nThanks for joining our community. If you have any questions, please don\'t hesitate to send them our way. Feel free to reply to this email directly.\n\nSincerely,\nThe Management',
            fromEmail: 'harold@example.enterprise',
            fromName: 'Harold Greaseworthy',
            }).exec({
            // An unexpected error occurred.
            error: function (err){

            },
            // OK.
            success: function (){

            },
        });    

    }
};

2 个答案:

答案 0 :(得分:1)

看看这个@DevArtisan Sails Email Service

希望它有所帮助!

答案 1 :(得分:0)

感谢。

我可以发送电子邮件但是不会在数据库中创建记录。我做的是重写创建控制器作为上面的代码,我不知道这是否会影响。或者我如何在创建数据库记录时发送电子邮件。