Skip to content

Commit

Permalink
fix: 🐛 Fix env variables in example server
Browse files Browse the repository at this point in the history
  • Loading branch information
5ika committed Aug 18, 2023
1 parent 89eab56 commit 8fc54f8
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions server-example/src/sendEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ 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/[email protected]/dotenv/mod.ts";

await load({ allowEmptyValues: true, examplePath: "" });
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"] || "";

export default (payload: FeedbackPayload) => {
if (emailTo)
Expand Down Expand Up @@ -35,12 +34,12 @@ const formatEmailContent = (payload: FeedbackPayload) => html`<div>
const sendEmail = async (config: Omit<SendConfig, "from">) => {
const client = new SMTPClient({
connection: {
hostname: Deno.env.get("SMTP_HOST") || "",
port: parseInt(Deno.env.get("SMTP_PORT") || "587"),
tls: Deno.env.get("SMTP_TLS") === "true",
hostname: envs["SMTP_HOST"] || "",
port: parseInt(envs["SMTP_PORT"] || "587"),
tls: envs["SMTP_TLS"] === "true",
auth: {
username: Deno.env.get("SMTP_USERNAME") || "",
password: Deno.env.get("SMTP_PASSWORD") || "",
username: envs["SMTP_USERNAME"] || "",
password: envs["SMTP_PASSWORD"] || "",
},
},
});
Expand All @@ -49,7 +48,7 @@ const sendEmail = async (config: Omit<SendConfig, "from">) => {
console.log(`Send email notification to ${emailTo}`);
const response = await client.send({
...config,
from: Deno.env.get("SMTP_SENDER") || "[email protected]",
from: envs["SMTP_SENDER"] || "[email protected]",
});

await client.close();
Expand Down

0 comments on commit 8fc54f8

Please sign in to comment.