58 lines
2.3 KiB
JavaScript
58 lines
2.3 KiB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
import nodemailer from "nodemailer";
|
|
import { respostaComuns } from "p-respostas";
|
|
// const confEmail = {
|
|
// host: "email-smtp.us-east-1.amazonaws.com",
|
|
// port: 587,
|
|
// secure: false,
|
|
// user: "AKIA2LGJTHGX2ZKMMYHG",
|
|
// pass: "BFuchUwoUYYDJK8l+pd1NvZxk70PjhMX+KbQy+5HfPDl",
|
|
// requireTLS: true,
|
|
// ignoreTLS: false,
|
|
// emailDe: "nao-responder@e-licencie.com.br",
|
|
// nomeDe: "🌱 Betha Meio Ambiente",
|
|
// };
|
|
const confEmail = {
|
|
host: "email-smtp.us-east-1.amazonaws.com",
|
|
port: 587,
|
|
secure: false,
|
|
user: "AKIA2LGJTHGX2ZKMMYHG",
|
|
pass: "BFuchUwoUYYDJK8l+pd1NvZxk70PjhMX+KbQy+5HfPDl",
|
|
requireTLS: true,
|
|
ignoreTLS: false,
|
|
emailDe: "nao-responder@gestao-ambiental-brasil.idz.one",
|
|
nomeDe: "🌱 Betha Meio Ambiente",
|
|
};
|
|
export const enviarEmail = ({ email, nome, assunto, texto, htlm, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
const info = yield nodemailer
|
|
.createTransport({
|
|
host: confEmail.host,
|
|
port: confEmail.port,
|
|
secure: confEmail.secure,
|
|
auth: {
|
|
user: confEmail.user,
|
|
pass: confEmail.pass,
|
|
},
|
|
})
|
|
.sendMail({
|
|
from: { address: confEmail.emailDe, name: confEmail.nomeDe },
|
|
to: nome ? { address: email, name: nome } : email,
|
|
subject: assunto,
|
|
text: texto,
|
|
html: htlm,
|
|
})
|
|
.then(() => respostaComuns.valor(`Email "${assunto}" enviado para ${email}`))
|
|
.catch((err) => {
|
|
console.error(err);
|
|
return respostaComuns.erro(`Erro ao enviar email para ${email}: ${err.message}`);
|
|
});
|
|
return info;
|
|
});
|