Last active
May 18, 2022 18:53
-
-
Save adsonrocha/5e2af81dcfe28991e726a6bcb069ce18 to your computer and use it in GitHub Desktop.
Como enviar e-mail usando Cloud Functions do Firebase com um projeto Ionic 3+ e Nodemailer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const functions = require('firebase-functions'); | |
const nodemailer = require('nodemailer'); | |
const cors = require('cors')({origin: true}); | |
let url = "smtps://<SEU-EMAIL>%40gmail.com:"+encodeURIComponent('<SUA-SENHA>') + "@smtp.gmail.com:465"; | |
let transporter = nodemailer.createTransport(url); | |
exports.enviarEmail = functions.https.onRequest((req, res) => { | |
cors(req, res, () => { | |
let remetente = '"Adson Rocha" <[email protected]>'; | |
let assunto = req.body['assunto']; | |
let destinatarios = req.body['destinatarios']; // lista de e-mails destinatarios separados por , | |
let corpo = req.body['corpo']; | |
let corpoHtml = req.body['corpoHtml']; | |
let email = { | |
from: remetente, | |
to: destinatarios, | |
subject: assunto, | |
text: corpo, | |
html: corpoHtml | |
}; | |
transporter.sendMail(email, (error, info) => { | |
if (error) { | |
return console.log(error); | |
} | |
console.log('Mensagem %s enviada: %s', info.messageId, info.response); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
amigo estou usando angular....fiz exatamente assim porém ele não envia o e-mail....