-
Hello, Has anyone figured out a way to move the core emails over to production? So let's say I design the account confirmation and password reset emails nicely on my dev machine, how do i "export" them? The export option is only for custom emails. If I try to alter the records in the DB directly in the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
For anyone who is wondering how I actually got this done, I had to do some digging to see how the creator of this package saved the core emails. The logic comes from here: https://github.com/alexzaganelli/strapi-plugin-email-designer/blob/main/server/controllers/designer.js#L158 I created a function that gets called inside the The file with the functions look like this const {
emailConfirmationDesign,
emailConfirmationTemplate,
} = require("./email-confirmation-string-design");
const {
resetPasswordDesign,
resetPasswordStringTemplate,
} = require("./reset-password-string-design");
const createConfirmAccountTemplate = async () => {
const pluginStoreEmailKey = "email_confirmation";
const pluginStore = await strapi.store({
environment: "",
type: "plugin",
name: "users-permissions",
});
const emailsConfig = await pluginStore.get({ key: "email" });
emailsConfig[pluginStoreEmailKey] = {
...emailsConfig[pluginStoreEmailKey],
options: {
...(emailsConfig[pluginStoreEmailKey]
? emailsConfig[pluginStoreEmailKey].options
: {}),
message: emailConfirmationTemplate
.replace(/{{/g, "<%")
.replace(/}}/g, "%>"),
object: "Hi <%= USER.firstName %>! Confirm Account",
},
design: emailConfirmationDesign,
};
await pluginStore.set({ key: "email", value: emailsConfig });
};
const createResetPasswordTemplate = async () => {
const pluginStoreEmailKey = "reset_password";
const pluginStore = await strapi.store({
environment: "",
type: "plugin",
name: "users-permissions",
});
const emailsConfig = await pluginStore.get({ key: "email" });
emailsConfig[pluginStoreEmailKey] = {
...emailsConfig[pluginStoreEmailKey],
options: {
...(emailsConfig[pluginStoreEmailKey]
? emailsConfig[pluginStoreEmailKey].options
: {}),
message: resetPasswordStringTemplate
.replace(/{{/g, "<%")
.replace(/}}/g, "%>"),
object: "Reset Password",
},
design: resetPasswordDesign,
};
await pluginStore.set({ key: "email", value: emailsConfig });
};
module.exports = {
createConfirmAccountTemplate,
createResetPasswordTemplate,
}; The exported functions are then called inside the bootstrap function. From the function, you can see where I am storing the email string and design object in different files(they are very long, had to put them in a different file) The design object I had to get from my datbase directly, while the template string I was able to copy from the UI's Settings>Email Templates section. |
Beta Was this translation helpful? Give feedback.
For anyone who is wondering how I actually got this done, I had to do some digging to see how the creator of this package saved the core emails. The logic comes from here: https://github.com/alexzaganelli/strapi-plugin-email-designer/blob/main/server/controllers/designer.js#L158
I created a function that gets called inside the
bootstrap
function located in the.src/index.js
file.The file with the functions look like this