Thursday 18 May 2017

senting email with nodemailer and firebase functions with custom email not gmail

I am trying to send a simple email with nodemailer and firebase functions, not GMAIL I use my GoDaddy email server

but I have this error on firebase functions console

{ Error: getaddrinfo ENOTFOUND mail.square-boat.gr mail.square-boat.gr:587
        at errnoException (dns.js:28:10)
        at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
      code: 'ECONNECTION',
      errno: 'ENOTFOUND',
      syscall: 'getaddrinfo',
      hostname: 'mail.square-boat.gr',
      host: 'mail.square-boat.gr',
      port: '587',
      command: 'CONN' }

this is the function's code on index.js

const mailTransport = nodemailer.createTransport({

  host: 'mail.square-boat.gr',
  auth: {
    user: 'info@square-boat.gr',
    pass: 'dtranq12!'
  },
  secure: false, // use TLS
  port : '587'

});


exports.sendContactMessage = functions.database.ref('/emails/{pushKey}').onWrite(event => {

  const snapshot = event.data;

  // Only send email for new messages.
  if (snapshot.previous.val() || !snapshot.val().name) {
    return;
  }

  const val = snapshot.val();

  const mailOptions = {
    from: 'test@example.com',
    to: 'test@example.com',
    subject: `Information Request from ${val.name}`,
    html: val.html
  };

  return mailTransport.sendMail(mailOptions).then(() => {
    return console.log('Mail sent to: test@example.com')
  }).catch( error => {
    console.log(error);
  });

});



via George hatouts

No comments:

Post a Comment