1

我正在爲Firebase和Nodemailer使用雲端函數,並將代碼放在了歡迎電子郵件中。以下是我的代碼有:使用雲端函數處理Firebase和節點郵件時創建用戶事件時發生無效登錄

const functions = require('firebase-functions'); 

const admin = require('firebase-admin'); 
admin.initializeApp(functions.config().firebase); 

const nodemailer = require('nodemailer'); 
const gmailEmail = encodeURIComponent(functions.config().gmail.email); 
const gmailPassword = encodeURIComponent(functions.config().gmail.password); 

const mailTransport = nodemailer.createTransport(
`smtps://${gmailEmail}:${gmailPassword}@smtp.gmail.com`); 
const APP_NAME = 'Test'; 

exports.sendWelcomeEmail = functions.auth.user().onCreate(event => { 
    const user = event.data; // The Firebase user. 
    const email = user.email; // The email of the user. 
    const displayName = user.displayName; // The display name of the user. 

    return sendWelcomeEmail(email, displayName); 
}); 


function sendWelcomeEmail(email, displayName) { 
    const mailOptions = { 
     from: '"Test" <[email protected]>', 
     to: email 
    }; 

    // The user subscribed to the newsletter. 
    mailOptions.subject = `Welcome to hell!`; 
    mailOptions.text = `Hey I hope you will enjoy our service.`; 
    return mailTransport.sendMail(mailOptions).then(() => { 
     console.log('New welcome email sent to:', email); 
    }); 
} 
  • 我有允許不夠安全的應用上
  • 轉身我看到我的Gmail地址和密碼的配置。我已經通過在命令行中鍵入firebase functions:config:get

我收到以下錯誤 Invalid Login even when credentials are correct

回答

1

我解決它只是使用了正確的電子郵件地址from:你把配置的一個驗證了這一點。

from: '"Test" <[email protected]>',

+0

我不想使用我的個人電子郵件地址。我希望使用[email protected] –

+0

對不起,我不認爲這是可能的。 從nodemailer文檔: 'Gmail也始終將驗證用戶名設置爲發件人:電子郵件地址。因此,如果您通過[email protected]進行身份驗證,並將[email protected]設置爲from:地址,則Gmail將恢復此操作,並將該發件人替換爲已通過身份驗證的用戶。# https://community.nodemailer.com/using- gmail/ – stefat

+0

我已經驗證過 'const gmailEmail = encodeURIComponent(functions.config()。gmail.email); const gmailPassword = encodeURIComponent(functions.config()。gmail.password);' –

相關問題