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); | |
}); | |
}); | |
}); |
Olá,
Você precisa habilitar as cobranças na sua conta firebase.
Em ter., 12 de jan. de 2021 às 21:26, Alberto Vieira de Lima <
[email protected]> escreveu:
… ***@***.**** commented on this gist.
------------------------------
Olá tudo bem?
Estou enfrentando este problema ao fazer o deploy da função:
Deployment error.
Failed to initialize region (action ID: 2effcce4c12aa6d3): Function deployment failed because the billing account is not available.
Functions deploy had errors with the following functions:
enviarEmail
To try redeploying those functions, run:
firebase deploy --only "functions:enviarEmail"
To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/5e2af81dcfe28991e726a6bcb069ce18#gistcomment-3591808>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIRRHSX6HWZDPQYRXFVUBLSZTSEXANCNFSM4WAAALMQ>
.
--
Prof. Dr. Adson Silva Rocha
[email protected]
http://www.ifgoiano.edu.br/trindade
amigo estou usando angular....fiz exatamente assim porém ele não envia o e-mail....
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Olá tudo bem?
Estou enfrentando este problema ao fazer o deploy da função: