From 2f334e2535788777c1cb3d01017607b08358ca06 Mon Sep 17 00:00:00 2001 From: Tim Izzo Date: Fri, 18 Aug 2023 17:02:55 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20env=20variables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server-example/src/sendEmail.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/server-example/src/sendEmail.ts b/server-example/src/sendEmail.ts index 5d70fb6..ea50da4 100644 --- a/server-example/src/sendEmail.ts +++ b/server-example/src/sendEmail.ts @@ -1,10 +1,13 @@ import { SMTPClient, SendConfig } from "https://deno.land/x/denomailer/mod.ts"; import { html } from "https://deno.land/x/html/mod.ts"; -import { load } from "https://deno.land/std@0.193.0/dotenv/mod.ts"; +import "https://deno.land/std@0.193.0/dotenv/load.ts"; -const envs = await load({ allowEmptyValues: true, examplePath: "" }); +const emailTo = + Deno.env.get("SMTP_RECEIVER") || Deno.env.get("SMTP_SENDER") || ""; -const emailTo = envs["SMTP_RECEIVER"] || envs["SMTP_SENDER"] || ""; +if (emailTo) { + console.log(`Email notifications will be send to ${emailTo}`); +} export default (payload: FeedbackPayload) => { if (emailTo) @@ -34,12 +37,12 @@ const formatEmailContent = (payload: FeedbackPayload) => html`
const sendEmail = async (config: Omit) => { const client = new SMTPClient({ connection: { - hostname: envs["SMTP_HOST"] || "", - port: parseInt(envs["SMTP_PORT"] || "587"), - tls: envs["SMTP_TLS"] === "true", + hostname: Deno.env.get("SMTP_HOST") || "", + port: parseInt(Deno.env.get("SMTP_PORT") || "587"), + tls: Deno.env.get("SMTP_TLS") === "true", auth: { - username: envs["SMTP_USERNAME"] || "", - password: envs["SMTP_PASSWORD"] || "", + username: Deno.env.get("SMTP_USERNAME") || "", + password: Deno.env.get("SMTP_PASSWORD") || "", }, }, }); @@ -48,7 +51,7 @@ const sendEmail = async (config: Omit) => { console.log(`Send email notification to ${emailTo}`); const response = await client.send({ ...config, - from: envs["SMTP_SENDER"] || "sender@example.org", + from: Deno.env.get("SMTP_SENDER") || "sender@example.org", }); await client.close();