servico de email incluido em drives
This commit is contained in:
parent
665386f17b
commit
ee9317406d
6 changed files with 250 additions and 1 deletions
9
dist-import/email/email.d.ts
vendored
Normal file
9
dist-import/email/email.d.ts
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { type tipoResposta } from "p-respostas";
|
||||
export declare const enviarEmail: ({ email, nome, assunto, texto, htlm, }: {
|
||||
email: string;
|
||||
nome?: string | undefined;
|
||||
assunto: string;
|
||||
/** Verão em texto do html, não obrigatório */
|
||||
texto?: string | undefined;
|
||||
htlm: string;
|
||||
}) => Promise<tipoResposta<string>>;
|
||||
58
dist-import/email/email.js
Normal file
58
dist-import/email/email.js
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
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;
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue