Skip to content

Commit

Permalink
🐛 Fix env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
5ika committed Aug 18, 2023
1 parent 85d9fd0 commit 2f334e2
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions server-example/src/sendEmail.ts
Original file line number Diff line number Diff line change
@@ -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/[email protected]/dotenv/mod.ts";
import "https://deno.land/[email protected]/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)
Expand Down Expand Up @@ -34,12 +37,12 @@ const formatEmailContent = (payload: FeedbackPayload) => html`<div>
const sendEmail = async (config: Omit<SendConfig, "from">) => {
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") || "",
},
},
});
Expand All @@ -48,7 +51,7 @@ const sendEmail = async (config: Omit<SendConfig, "from">) => {
console.log(`Send email notification to ${emailTo}`);
const response = await client.send({
...config,
from: envs["SMTP_SENDER"] || "[email protected]",
from: Deno.env.get("SMTP_SENDER") || "[email protected]",
});

await client.close();
Expand Down

0 comments on commit 2f334e2

Please sign in to comment.