As to my knowledge, strapi does not provide any options to set the email urls via the environment variable. So I included it into the strapi bootstrap function. It relies on the environment variable common.emails.resetPasswordUrl
:
// index.ts
import type { Core } from "@strapi/strapi"
async function setEmailConfiguration(strapi: Core.Strapi) {
strapi.log.info("✉️ Setting email configuration...")
const resetPasswordUrl = strapi.config.get("common.emails.resetPasswordUrl")
strapi.log.info(`✉️ Reset password Url: ${resetPasswordUrl}`)
if (!resetPasswordUrl) {
strapi.log.warn(
"No reset password URL found. Maybe you need to add it in the strapi backend.",
)
return
}
const pluginStore = await strapi.store({
type: "plugin",
name: "users-permissions",
})
const advancedSettings = (await pluginStore.get({
key: "advanced",
})) as object
await pluginStore.set({
key: "advanced",
value: {
...advancedSettings,
email_reset_password: resetPasswordUrl,
},
})
}
// ...
export default {
register({ strapi }: { strapi: Core.Strapi }) {
strapi.log.info("Strapi registered for TypeScript usage 🎉")
},
bootstrap({ strapi }: { strapi: Core.Strapi }) {
setEmailConfiguration(strapi)
},
}
And that's how a config/common.ts
configuration file could look like:
module.exports = ({ env }) => ({
emails: {
resetPasswordUrl: env("RESET_PASSWORD_URL"),
},
})
I did not add it to the config/plugins.ts
file, because to my knowledge I can't access the environment variables there.