Skip to content
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

(self host 1/?): allow users to configure their own email service #972

Merged
merged 4 commits into from
Feb 12, 2025

Conversation

tefkah
Copy link
Member

@tefkah tefkah commented Feb 12, 2025

  • feat: allow different email providers to be used when self-hosting, or allow users to disable email
  • fix: handle errors and fix types

Issue(s) Resolved

Partially #954

Note

I will base the other self host prs on this one, but that does not mean we necessarily need to merge it!
If for some reason we do not want to allow users to use different email providers (?)

This allows users to pick a different email provider somewhat easily.

High-level Explanation of PR

Adds some documentation and presets on how to use different email providers with platfrom.

Additionally, this makes the MAILGUN_ env vars optional for self hosting. This will then only throw an error when you try to use the email client.
I don't want users to NEED to configure an email client. They should probably, but it should be possible to run one without.

I also considered adding an option to use the native sendmail or msmtp or equivalent, but I'm not sure we should encourage that.

Ideally I would have made this more typesafe by making our config a discriminated union, eg

z.object({ 
	SELF_HOST: z.literal("true"),
	MAILGUN_SMTP_HOST: z.string.optional(), 
// etc, all optional
}).or(z.object({
	SELF_HOST: z.undefined(),
	MAILGUN_SMTP_HOST: z.string()
	// etc, most required
}))

However this does not seem possible, so instead i have this weird wrapper

/**
* Parameters which are optional if the app is self-hosted
* but we do want checked for our AWS deploys
*
* @template {import("zod").ZodTypeAny} Z
* @param {Z} schema
*/
const selfHostedOptional = (schema) => {
return process.env.SELF_HOSTED ? schema.optional() : schema;
};

Test Plan

  1. Create an app password for your Google account
  2. Configure the MAILGUN variables as such
    #### GMail
    To use GMail to relay emails through PubPub, you will need to create an [app password](https://support.google.com/accounts/answer/185833?hl=en).
    You will be limited to 2000 emails per day by default this way.
    ```sh
    MAILGUN_SMTP_HOST="smtp.gmail.com"
    MAILGUN_SMTP_PORT=587 # or 465 for SSL
    MAILGUN_SMTP_USERNAME="[email protected]"
    MAILGUN_SMTP_PASSWORD="your app password" # this will be a 16 character string
    MAILGUN_SMTP_FROM="[email protected]" # technically optional, but you will almost definitely need to set this.
    MAILGUN_SMTP_FROM_NAME="Your Organization" # Optional, will default to "PubPub Team"
    ```
  3. Send an email to a different email account than the one you configured
  4. See it appear like magic

  1. Also test the default mailgun config with the prod vars if possible (i do not have these i think)

Screenshots (if applicable)

Notes

the variables probably should not be prefixed by MAILGUN_, but i don't like messing with the terraform config.

@tefkah tefkah requested review from 3mcd and kalilsn February 12, 2025 13:50
@tefkah tefkah marked this pull request as ready for review February 12, 2025 13:50
Copy link
Member

@kalilsn kalilsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, though I do think we should drop the MAILGUN_ prefix. I can do it in a separate PR if you'd like since I don't mind messing with terraform

self-host/README.md Outdated Show resolved Hide resolved
self-host/README.md Outdated Show resolved Hide resolved
MAILGUN_SMTP_PORT=587
MAILGUN_SMTP_USERNAME="[email protected]"
MAILGUN_SMTP_PASSWORD="your-password"
MAILGUN_SMTP_FROM="[email protected]" # technically optional, but you will almost definitely need to set this, as it will use `[email protected]` by default.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to add this longer comment to the above "From" configs too. Though honestly I think we should make it and name required instead of having our defaults hardcoded.

Copy link
Member Author

@tefkah tefkah Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree. although i think this should be a community level config, not an installation wide one, which i why i left it for now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that sounds right to me! We shouldn't let people send arbitrary emails under our name 😟

@3mcd 3mcd merged commit 40074da into main Feb 12, 2025
6 checks passed
@3mcd 3mcd deleted the tfk/self-host branch February 12, 2025 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants