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: "",
|
||||
smtpPort: "",
|
||||
smtpUser: "",
|
||||
smtpPassword: "",
|
||||
encryption: "NONE",
|
||||
events: getDefaultEventsConfiguration(),
|
||||
};
|
||||
|
|
|
@ -2,34 +2,6 @@ import { z } from "zod";
|
|||
import { messageEventTypes } from "../../event-handlers/message-event-types";
|
||||
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({
|
||||
active: z.boolean(),
|
||||
eventType: z.enum(messageEventTypes),
|
||||
|
@ -45,6 +17,7 @@ export const mjmlConfigurationBaseObjectSchema = z.object({
|
|||
smtpHost: z.string().min(1),
|
||||
smtpPort: z.string(),
|
||||
smtpUser: z.string(),
|
||||
smtpPassword: z.string(),
|
||||
encryption: z.enum(smtpEncryptionTypes),
|
||||
});
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ export interface MjmlConfiguration {
|
|||
smtpHost: string;
|
||||
smtpPort: string;
|
||||
smtpUser: string;
|
||||
smtpPassword: string;
|
||||
encryption: SmtpEncryptionType;
|
||||
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
|
||||
control={control}
|
||||
name="encryption"
|
||||
|
|
|
@ -5,10 +5,14 @@ const logger = pinoLogger.child({
|
|||
fn: "sendEmailWithSmtp",
|
||||
});
|
||||
|
||||
interface SendMailArgs {
|
||||
export interface SendMailArgs {
|
||||
smtpSettings: {
|
||||
host: string;
|
||||
port: number;
|
||||
auth?: {
|
||||
user: string;
|
||||
pass: string | undefined;
|
||||
};
|
||||
};
|
||||
mailData: {
|
||||
from: string;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { logger as pinoLogger } from "../../lib/logger";
|
||||
import { compileMjml } from "./compile-mjml";
|
||||
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 { htmlToPlaintext } from "./html-to-plaintext";
|
||||
import { MjmlConfiguration } from "./configuration/mjml-config";
|
||||
|
@ -128,7 +128,7 @@ export const sendMjml = async ({
|
|||
};
|
||||
}
|
||||
|
||||
const { response, errors: smtpErrors } = await sendEmailWithSmtp({
|
||||
const sendEmailSettings: SendMailArgs = {
|
||||
mailData: {
|
||||
text: emailBodyPlaintext,
|
||||
html: emailBodyHtml,
|
||||
|
@ -140,7 +140,16 @@ export const sendMjml = async ({
|
|||
host: mjmlConfiguration.smtpHost,
|
||||
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) {
|
||||
return { errors: smtpErrors };
|
||||
|
|
Loading…
Reference in a new issue