Nodemailer not working with firebase cloud function

  Kiến thức lập trình

Hi so I’ve been trying to send an email with a cloud function but it’s not working, although it doesn’t return an error. I’ve tried to tweak things here and there but it just seems to not send an email. Not sure what to do from here, but this is what I have so far:

const functions = require("firebase-functions");
const admin = require("firebase-admin");
const nodemailer = require("nodemailer");

admin.initializeApp();

const SENDER_EMAIL = "my email";
const SENDER_PASSWORD = "password";   

// Function to send a verification code via email

const transporter = nodemailer.createTransport({
    service: 'gmail',
    type: "SMTP",
    host: "smtp.gmail.com",
    secure: true,
    auth: {
      user: 'email',
      pass: 'password'
    }
  });




exports.sendVerificationCode = functions.https.onCall((request) => {



  const mailOptions = {
    from: 'xxxxxx',
    to: 'xxxxx',
    subject: 'Email from Firebase',
    text: 'TEST TEST'
  };
  transporter.sendMail(mailOptions, (error, info) => {
    if (error) {
      console.log(error);
      res.send('Error sending email');
    } else {
      console.log('Email sent: ' + info.response);
      res.send('Email sent successfully');
    }
  });


});

here is how I call it from my swift app

   func sendVerificationCode(to email: String, uid: String) {
        let functions = Functions.functions()
        
        functions.httpsCallable("sendVerificationCode").call([]) { result, error in
            if let error = error {
                print("Error sending verification code: (error.localizedDescription)")
            } else {
                print("Verification code sent successfully.")
            }
        }

Recognized by Google Cloud Collective

2

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT