parent
c952624dd9
commit
a44aaf00a5
7 changed files with 40 additions and 32 deletions
5
.changeset/seven-sheep-watch.md
Normal file
5
.changeset/seven-sheep-watch.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"saleor-app-emails-and-messages": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixed SMTP auth data not being properly passed to the sending service
|
|
@ -22,6 +22,7 @@ export const getDefaultEmptyConfiguration = (): MjmlConfiguration => {
|
||||||
smtpHost: "",
|
smtpHost: "",
|
||||||
smtpPort: "",
|
smtpPort: "",
|
||||||
smtpUser: "",
|
smtpUser: "",
|
||||||
|
smtpPassword: "",
|
||||||
encryption: "NONE",
|
encryption: "NONE",
|
||||||
events: getDefaultEventsConfiguration(),
|
events: getDefaultEventsConfiguration(),
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,34 +2,6 @@ import { z } from "zod";
|
||||||
import { messageEventTypes } from "../../event-handlers/message-event-types";
|
import { messageEventTypes } from "../../event-handlers/message-event-types";
|
||||||
import { smtpEncryptionTypes } from "./mjml-config";
|
import { smtpEncryptionTypes } from "./mjml-config";
|
||||||
|
|
||||||
export const mjmlConfigInputSchema = z.object({
|
|
||||||
configurations: z.array(
|
|
||||||
z.object({
|
|
||||||
active: z.boolean(),
|
|
||||||
configurationName: z.string(),
|
|
||||||
senderName: z.string(),
|
|
||||||
senderEmail: z.string().email(),
|
|
||||||
smtpHost: z.string(),
|
|
||||||
smtpPort: z.string(),
|
|
||||||
smtpUser: z.string().min(0),
|
|
||||||
useTls: z.boolean(),
|
|
||||||
useSsl: z.boolean(),
|
|
||||||
templateInvoiceSentSubject: z.string(),
|
|
||||||
templateInvoiceSentTemplate: z.string(),
|
|
||||||
templateOrderCancelledSubject: z.string(),
|
|
||||||
templateOrderCancelledTemplate: z.string(),
|
|
||||||
templateOrderConfirmedSubject: z.string(),
|
|
||||||
templateOrderConfirmedTemplate: z.string(),
|
|
||||||
templateOrderFullyPaidSubject: z.string(),
|
|
||||||
templateOrderFullyPaidTemplate: z.string(),
|
|
||||||
templateOrderCreatedSubject: z.string(),
|
|
||||||
templateOrderCreatedTemplate: z.string(),
|
|
||||||
templateOrderFulfilledSubject: z.string(),
|
|
||||||
templateOrderFulfilledTemplate: z.string(),
|
|
||||||
})
|
|
||||||
),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const mjmlConfigurationEventObjectSchema = z.object({
|
export const mjmlConfigurationEventObjectSchema = z.object({
|
||||||
active: z.boolean(),
|
active: z.boolean(),
|
||||||
eventType: z.enum(messageEventTypes),
|
eventType: z.enum(messageEventTypes),
|
||||||
|
@ -45,6 +17,7 @@ export const mjmlConfigurationBaseObjectSchema = z.object({
|
||||||
smtpHost: z.string().min(1),
|
smtpHost: z.string().min(1),
|
||||||
smtpPort: z.string(),
|
smtpPort: z.string(),
|
||||||
smtpUser: z.string(),
|
smtpUser: z.string(),
|
||||||
|
smtpPassword: z.string(),
|
||||||
encryption: z.enum(smtpEncryptionTypes),
|
encryption: z.enum(smtpEncryptionTypes),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ export interface MjmlConfiguration {
|
||||||
smtpHost: string;
|
smtpHost: string;
|
||||||
smtpPort: string;
|
smtpPort: string;
|
||||||
smtpUser: string;
|
smtpUser: string;
|
||||||
|
smtpPassword: string;
|
||||||
encryption: SmtpEncryptionType;
|
encryption: SmtpEncryptionType;
|
||||||
events: MjmlEventConfiguration[];
|
events: MjmlEventConfiguration[];
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,6 +258,21 @@ export const MjmlConfigurationForm = (props: Props) => {
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="smtpPassword"
|
||||||
|
control={control}
|
||||||
|
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
||||||
|
<TextField
|
||||||
|
label="SMTP server password"
|
||||||
|
value={value}
|
||||||
|
helperText={error?.message}
|
||||||
|
error={!!error}
|
||||||
|
onChange={onChange}
|
||||||
|
{...CommonFieldProps}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="encryption"
|
name="encryption"
|
||||||
|
|
|
@ -5,10 +5,14 @@ const logger = pinoLogger.child({
|
||||||
fn: "sendEmailWithSmtp",
|
fn: "sendEmailWithSmtp",
|
||||||
});
|
});
|
||||||
|
|
||||||
interface SendMailArgs {
|
export interface SendMailArgs {
|
||||||
smtpSettings: {
|
smtpSettings: {
|
||||||
host: string;
|
host: string;
|
||||||
port: number;
|
port: number;
|
||||||
|
auth?: {
|
||||||
|
user: string;
|
||||||
|
pass: string | undefined;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
mailData: {
|
mailData: {
|
||||||
from: string;
|
from: string;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { logger as pinoLogger } from "../../lib/logger";
|
import { logger as pinoLogger } from "../../lib/logger";
|
||||||
import { compileMjml } from "./compile-mjml";
|
import { compileMjml } from "./compile-mjml";
|
||||||
import { compileHandlebarsTemplate } from "./compile-handlebars-template";
|
import { compileHandlebarsTemplate } from "./compile-handlebars-template";
|
||||||
import { sendEmailWithSmtp } from "./send-email-with-smtp";
|
import { sendEmailWithSmtp, SendMailArgs } from "./send-email-with-smtp";
|
||||||
import { MessageEventTypes } from "../event-handlers/message-event-types";
|
import { MessageEventTypes } from "../event-handlers/message-event-types";
|
||||||
import { htmlToPlaintext } from "./html-to-plaintext";
|
import { htmlToPlaintext } from "./html-to-plaintext";
|
||||||
import { MjmlConfiguration } from "./configuration/mjml-config";
|
import { MjmlConfiguration } from "./configuration/mjml-config";
|
||||||
|
@ -128,7 +128,7 @@ export const sendMjml = async ({
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const { response, errors: smtpErrors } = await sendEmailWithSmtp({
|
const sendEmailSettings: SendMailArgs = {
|
||||||
mailData: {
|
mailData: {
|
||||||
text: emailBodyPlaintext,
|
text: emailBodyPlaintext,
|
||||||
html: emailBodyHtml,
|
html: emailBodyHtml,
|
||||||
|
@ -140,7 +140,16 @@ export const sendMjml = async ({
|
||||||
host: mjmlConfiguration.smtpHost,
|
host: mjmlConfiguration.smtpHost,
|
||||||
port: parseInt(mjmlConfiguration.smtpPort, 10),
|
port: parseInt(mjmlConfiguration.smtpPort, 10),
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (mjmlConfiguration.smtpUser) {
|
||||||
|
sendEmailSettings.smtpSettings.auth = {
|
||||||
|
user: mjmlConfiguration.smtpUser,
|
||||||
|
pass: mjmlConfiguration.smtpPassword,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const { response, errors: smtpErrors } = await sendEmailWithSmtp(sendEmailSettings);
|
||||||
|
|
||||||
if (smtpErrors?.length) {
|
if (smtpErrors?.length) {
|
||||||
return { errors: smtpErrors };
|
return { errors: smtpErrors };
|
||||||
|
|
Loading…
Reference in a new issue