-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add admin mailer. #103
Merged
+468
−50
Merged
Add admin mailer. #103
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
fad94df
Add admin mailer.
scosman a70edfa
Add docs for admin mailer
scosman 14d3ca9
Make nodemailer optional, see if this fixed cloudflare
scosman bbda648
Move nodemailer types to dev only dep
scosman 1074e5c
Handle exception on nodemailer import
scosman e5484da
remove nodemailer from package.lock
scosman d12ea05
Add cloudflare worker support
scosman 0a6a2da
Nodemailer defined on CF?
scosman f1e4067
test CF
scosman 62f4df1
test CF
scosman f0fc32a
test CF
scosman 31071b1
test CF
scosman ebd2e1e
test CF
scosman f5f8307
test CF
scosman 07421de
test CF
scosman 97799c6
test CF
scosman 237850b
test CF
scosman accb4c4
test CF
scosman b136506
test CF
scosman 428b3a5
test CF
scosman 468ef61
test CF
scosman 552fe69
test CF
scosman 84e1b13
test CF
scosman 1f1a017
test CF
scosman 81585f7
test CF
scosman 1568777
test CF
scosman 3b8defc
test CF
scosman 04be4e3
test CF
scosman 1fbd525
test CF
scosman 6eb3369
test CF
scosman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
# Supabase settings | ||
PUBLIC_SUPABASE_URL='https://REPLACE_ME.supabase.co' | ||
PUBLIC_SUPABASE_ANON_KEY='REPLACE_ME' | ||
PRIVATE_SUPABASE_SERVICE_ROLE='REPLACE_ME' | ||
|
||
# Stripe settings | ||
PRIVATE_STRIPE_API_KEY='REPLACE_ME' | ||
|
||
# SMTP settings for email - optional | ||
# PRIVATE_ADMIN_EMAIL='[email protected]' # see lib/admin_mailer.ts | ||
# PRIVATE_SMTP_HOST='REPLACE_ME' | ||
# PRIVATE_SMTP_PORT='587' | ||
# PRIVATE_SMTP_USER='REPLACE_ME' | ||
# PRIVATE_SMTP_PASS='REPLACE_ME' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import nodemailer from "nodemailer" | ||
|
||
import { env } from "$env/dynamic/private" | ||
|
||
// Sends an email to the admin email address. | ||
// Does not throw errors, but logs them. | ||
export const sendAdminEmail = async ({ | ||
subject, | ||
body, | ||
}: { | ||
subject: string | ||
body: string | ||
}) => { | ||
// Check admin email is set. | ||
if (!env.PRIVATE_ADMIN_EMAIL) { | ||
return | ||
} | ||
|
||
// Check if smtp settings are set. | ||
if ( | ||
!env.PRIVATE_SMTP_HOST || | ||
!env.PRIVATE_SMTP_USER || | ||
!env.PRIVATE_SMTP_PASS | ||
) { | ||
console.log( | ||
"No smtp settings, not sending admil email. See CMSaasStarter setup instructions.", | ||
) | ||
return | ||
} | ||
|
||
// Default to port 587 if not set. | ||
let port = 587 | ||
if (env.PRIVATE_SMTP_PORT) { | ||
port = parseInt(env.PRIVATE_SMTP_PORT) | ||
} | ||
|
||
try { | ||
const transporter = nodemailer.createTransport({ | ||
host: env.PRIVATE_SMTP_HOST, | ||
port: port, | ||
secure: port === 465, // https://nodemailer.com/smtp/ | ||
requireTLS: true, // Email should be encrypted in 2024 | ||
auth: { | ||
user: env.PRIVATE_SMTP_USER, | ||
pass: env.PRIVATE_SMTP_PASS, | ||
}, | ||
}) | ||
|
||
const info = await transporter.sendMail({ | ||
from: env.PRIVATE_ADMIN_EMAIL, | ||
to: env.PRIVATE_ADMIN_EMAIL, | ||
subject: "ADMIN_MAIL: " + subject, | ||
text: body, | ||
}) | ||
|
||
if (info.rejected && info.rejected.length > 0) { | ||
console.log("Failed to send admin email, rejected:", info.rejected) | ||
} | ||
} catch (e) { | ||
console.log("Failed to send admin email, error:", e) | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix grammatical error: "Setup" should be "Set up".
The word "setup" is a noun. The verb form is "set up".
Committable suggestion