使用自定义电子邮件而非gmail发送带有nodemailer和firebase功能的电子邮件

时间:2017-05-18 07:39:21

标签: node.js angular firebase nodemailer google-cloud-functions

我正在尝试发送一个简单的电子邮件,其中包含用于Firebase的nodemailer和Cloud功能,而不是GMAIL我使用的是GoDaddy电子邮件服务器,但我在Firebase控制台的Cloud Functions上出现此错误:

{ 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' }

这是index.js上的函数代码:

const mailTransport = nodemailer.createTransport({

  host: 'mail.square-boat.gr',
  auth: {
    user: 'info@square-boat.gr',
    pass: 'xxxxx!'
  },
  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);
  });

});

0 个答案:

没有答案