2017-06-08 14 views
9

जब मैं /emails में कुछ भी लिखा गया है, तो मैं अपने ईमेल पर एक टेस्ट ईमेल भेजने की कोशिश कर रहा हूं लेकिन ईमेल कभी नहीं भेजा जाता है और फ़ंक्शन लॉग खाली होते हैं।फायरबेस के लिए क्लाउड फ़ंक्शंस - ईमेल पर भेजें

exports.sendTestEmail = functions.database.ref('/emails') 
    .onWrite(event => { 
    return sendTestEmail('[email protected]'); 
    }) 
// [END onWrite] 

// Sends a welcome email to the given user. 
function sendTestEmail(email) { 
    const mailOptions = { 
    from: `${APP_NAME} <[email protected]>`, 
    to: email 
    }; 
    // The user subscribed to the newsletter. 
    mailOptions.subject = `Welcome to ${APP_NAME}!`; 
    mailOptions.text = `Hey there! Welcome to ${APP_NAME}. I hope you will enjoy our service.`; 
    return mailTransport.sendMail(mailOptions).then(() => { 
    console.log('New welcome email sent to:', email); 
    }); 

} 

संपादित ***

ऊपर कोड काम करता है। मैं emails पर फ़ंक्शन ट्रिगर करने का प्रयास कर रहा था, जबकि सही नाम email था।

+0

क्या आप जीएमएल को अपनी एसएमटीपी सेवा के रूप में उपयोग कर रहे हैं? यदि आप हैं, तो Google की सुरक्षा के कारण आपको अपने व्यक्तिगत पासवर्ड के बजाय ऐप पासवर्ड का उपयोग करने की आवश्यकता हो सकती है। ऐसा करने का एक तरीका यहां है https://support.google.com/accounts/answer/185833?hl=hi – Tobidae

+0

हाँ मैं हूं। समस्या यह है कि जब उपयोगकर्ता खाते बनाते हैं तो मैं उसी प्रारूप का उपयोग करके ईमेल भेजता हूं। और वह काम करता है। – Ciprian

+0

प्रेषण पर त्रुटियों को पकड़ने का प्रयास करें: 'mailTransport.sendMail (mailOptions) .then (...)। पकड़ें (त्रुटि => {console.error ('त्रुटि भेजने:', त्रुटि);});' –

उत्तर

3

फायरबेस क्लाउड फ़ंक्शंस का उपयोग करके ईमेल भेजने का सही तरीका!

exports.sendTestEmail = functions.database.ref('/emails') 
    .onWrite(event => { 
    return sendTestEmail('[email protected]'); 
    }) 
// [END onWrite] 

// Sends a welcome email to the given user. 
function sendTestEmail(email) { 
    const mailOptions = { 
    from: `${APP_NAME} <[email protected]>`, 
    to: email 
    }; 
    // The user subscribed to the newsletter. 
    mailOptions.subject = `Welcome to ${APP_NAME}!`; 
    mailOptions.text = `Hey there! Welcome to ${APP_NAME}. I hope you will enjoy our service.`; 
    return mailTransport.sendMail(mailOptions).then(() => { 
    console.log('New welcome email sent to:', email); 
    }); 

} 
संबंधित मुद्दे