Skip to content

Instantly share code, notes, and snippets.

@adsonrocha
Last active May 18, 2022 18:53
Show Gist options
  • Save adsonrocha/5e2af81dcfe28991e726a6bcb069ce18 to your computer and use it in GitHub Desktop.
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
'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@gmail.com>';
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);
});
});
});
@avlima
Copy link

avlima commented Jan 13, 2021

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.

@adsonrocha
Copy link
Author

adsonrocha commented Jan 13, 2021 via email

@tikaoo
Copy link

tikaoo commented May 18, 2022

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