-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from AshishBarvaliya/dev
fix: sendmail debug
- Loading branch information
Showing
15 changed files
with
151 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { getEmailHtml } from "@/constants/email"; | ||
import path from "path"; | ||
import nodemailer from "nodemailer"; | ||
|
||
const host = process.env.MAIL_SMTP_HOST; | ||
const port = Number(process.env.MAIL_SMTP_PORT || "587"); | ||
const user = process.env.MAIL_SMTP_USER; | ||
const pass = process.env.MAIL_SMTP_PASS; | ||
|
||
if (!host || !port || !user || !pass) { | ||
throw new Error("Missing SMTP credentials"); | ||
} | ||
|
||
let transporter = nodemailer.createTransport({ | ||
host, | ||
port, | ||
auth: { | ||
user, | ||
pass, | ||
}, | ||
}); | ||
|
||
export const sendEmail = ( | ||
type: "reset-password" | "activation" | "welcome", | ||
{ email, token, name }: { email: string; token: string; name: string } | ||
) => { | ||
const inlineImage = { | ||
filename: "logo.png", | ||
path: path.join(process.cwd(), "public", "logo.png"), | ||
cid: "logo.png", | ||
}; | ||
|
||
return transporter.sendMail({ | ||
from: `ThemeAI.io ${user}`, | ||
to: email, | ||
subject: | ||
type === "reset-password" | ||
? "Reset your password" | ||
: "Verify your ThemeAI account", | ||
html: getEmailHtml(type, { token, name }), | ||
attachments: [inlineImage], | ||
}); | ||
}; |
Oops, something went wrong.