1

I have the following function which triggers when the value of the (requested service status) changes in my Database:

exports.cheackUserService = functions.database.ref('Users/{userID}/requested service status').onWrite((event) => {

    var requestedServiceStatus = event.data.val();
    var userId = event.params.userID;

    var mailgun = require("mailgun-js");
    var api_key = 'key-XXXXXXXXXXXXXX';
    var DOMAIN = 'sandbox76c6f74ddab14862816390c16f37a272.mailgun.org';
    var mailgun = require('mailgun-js')({apiKey: api_key, domain: DOMAIN});

    var data = {
        from: 'Excited User <postmaster@sandbox76c6f74ddab14862816390c16f37a272.mailgun.org>',
        to: 'rayteamstudio@gmail.com',
        subject: 'Complex',
        text: 'Testing some Mailgun awesomness!',
    };

    console.log('data: ',data);

    mailgun.messages().send(data, function (error, body) {
        console.log('error: ',error);
    });
});

The function executes just fine but the email never gets send. Instead, it logs this error:

error:  { Error: getaddrinfo ENOTFOUND api.mailgun.net api.mailgun.net:443
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'api.mailgun.net',
  host: 'api.mailgun.net',
  port: 443 }

Can someone help please?

Note: the email(rayteamstudio@gmail.com) is the email I used to create the mailgun account.

0 Answers0