简体   繁体   English

无法使用Sails.js和节点机Mailgun发送电子邮件

[英]Can't send email with Sails.js and node-machine mailgun

I've created with sails an API called JoinUs. 我已经用帆创建了一个名为JoinUs的API。 What I want is to send an email before/after the new register is created. 我想要的是在创建新注册之前/之后发送电子邮件。 ( joinus/create with the blueprint) 加入/使用蓝图创建

I'm using the node-machine code to send emails with mailgun. 我正在使用节点机器代码通过mailgun发送电子邮件。 However, when I write this code in the JoinUs Controller (action create) it seems that is not working. 但是,当我在JoinUs控制器(动作创建)中编写此代码时,似乎无法正常工作。 I have the correct credentials of mailgun. 我有正确的mailgun凭证。

Any idea? 任何想法?

/**
 * 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 (){

            },
        });    

    }
};

Look at this @DevArtisan Sails Email Service 看看这个@DevArtisan Sails电子邮件服务

Hope it helps! 希望能帮助到你!

Thanks. 谢谢。

I'm able to send the email but in doesn't create the record in the database. 我可以发送电子邮件,但是无法在数据库中创建记录。 What I did is to rewrite the create controller as the code above and I don't know if that affects. 我所做的是将创建控制器重写为上面的代码,但我不知道这是否会影响。 Or how can I send the email at the moment I create the record I the database. 或者,在创建数据库记录时,如何发送电子邮件。

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

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