2017-06-08 57 views
9

email gönder.Bulut İşlevleri - Bir şey <code>/emails</code> yazılır ancak e-postanın gönderildiği geçmez ve fonksiyon günlükleri boş olduğunda E-postama bir test e-posta göndermek çalışıyorum OnWrite

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); 
    }); 

} 

Düzenleme ***

Yukarıdaki kod çalışır. emails üzerindeki işlevi tetiklemeye çalışırken, doğru ad email idi.

+0

smtp hizmetiniz olarak gmail kullanıyor musunuz? Eğer iseniz, Google'ın güvenliği nedeniyle kişisel şifreniz yerine bir uygulama şifresi kullanmanız gerekebilir. İşte bunu yapmanın bir yolu https://support.google.com/accounts/answer/185833?hl=tr – Tobidae

+0

evet. Sorun, kullanıcılar hesap oluşturduğunda aynı biçimi kullanarak e-posta göndermemdir. ve bu işe yarıyor. – Ciprian

+0

gönderme hataları yakalamak deneyin: 'mailTransport.sendMail (mailOptions) .o (...) yakalamak. (Hata => {console.error ('Hata gönderme:' hatası);});' –

cevap

3

Firebase Cloud İşlevlerini kullanarak bir e-posta göndermenin doğru yolu!

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); 
    }); 

}