简体   繁体   中英

SMTP Firebase Application

So I've been looking at several of the answers to questions on StackOverflow, reading blogs, watching tutorials... And I'm not having luck with trying to send an email through SMTP with Firebase Cloud Functions using Gmail in response to an HTTP request. I've enrolled in payments and tried using third parties like Mailgun and I have issues with that as well. Here is the error I'm getting with Gmail SMTP.

{ Error: connect ETIMEDOUT 173.194.74.17:465
at Object.exports._errnoException (util.js:1020:11)
at exports._exceptionWithHostPort (util.js:1043:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
code: 'ECONNECTION',
  errno: 'ETIMEDOUT',
  syscall: 'connect',
  address: '173.194.74.17',
  port: 465,
  command: 'CONN' }

This is the code I'm currently using:

var transporter = nodemailer.createTransport('smtps://email@gmail.com:password')

function sendTestEmail(user) {
  ref.child('users').child(user).once('value').then(snap => {
    console.log(snap.val()["Email"])// will be 'email' when looking at angels and not users
    const mailOptions = {
      from: '"The Angel App" <email@gmail.com>',
      bcc: snap.val()['Email'],
      subject: "This is a test for missed checkins",
      text: "Testing the cloud functions"
    }
    return transporter.sendMail(mailOptions).then(() => {
      console.log("email sent to ", user)
      return "email sent"
    }).catch(error => {
      console.log(error)
    })
  }).catch(error => {
    console.log(error)
  })

I've also done:

// const transporter = nodemailer.createTransport({
//   host: 'smtp.gmail.com', 
//   port: 465,
//   secure: true,
//   auth: {
//     user: 'email@gmail.com',
//     pass: 'password'
//   }
// })

At first I got an anti fraud email from Gmail saying that an app was trying to log in and to edit my settings if it was me. So I did. Any insight would be great.

So I decided to try something different and created a business email through zoho and it worked. I made the transporter:

const transporter = nodemailer.createTransport({
  host: 'smtp.zoho.com', 
  port: 465,
  secure: true,
  auth: {
    user: 'noreply@jacobzivandesign.com',
    pass: 'password'
  }
})

Important change I had to make in the sendTestEmail function was in the From line

function sendTestEmail(user) {
  ref.child('users').child(user).once('value').then(snap => {
    console.log(snap.val()["Email"])// will be 'email' when looking at angels and not users
    const mailOptions = {
      from: '"The Angel App" <noreply@jacobzivandesign.com>',
      bcc: snap.val()['Email'],
      subject: "This is a test for missed checkins",
      text: "Testing the cloud functions"
    }
    return transporter.sendMail(mailOptions).then(() => {
      console.log("email sent to ", user)
      return "email sent"
    }).catch(error => {
      console.log(error)
    })
  }).catch(error => {
    console.log(error)
  })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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