
* Extract logger * Replace logger with shared one * Replace CRM logger with shared one * Replace E&M logger with shared one * Replace invoices logger with shared one * Replace Products Feed logger with shared one * Replace Search logger with shared one * Replace Taxes logger with shared one * Uninstall pino from apps direct dependency * Update docs * Update changeset * Bumped Klaviyo typescript version to hopefully unblock the build * Change packageManager field to pnpm 8.2.0 * removed package manager field from klaviyo package.json
47 lines
1 KiB
TypeScript
47 lines
1 KiB
TypeScript
import nodemailer from "nodemailer";
|
|
import { createLogger } from "@saleor/apps-shared";
|
|
|
|
const logger = createLogger({
|
|
fn: "sendEmailWithSmtp",
|
|
});
|
|
|
|
export interface SendMailArgs {
|
|
smtpSettings: {
|
|
host: string;
|
|
port: number;
|
|
auth?: {
|
|
user: string;
|
|
pass: string | undefined;
|
|
};
|
|
};
|
|
mailData: {
|
|
from: string;
|
|
to: string;
|
|
text: string;
|
|
html: string;
|
|
subject: string;
|
|
};
|
|
}
|
|
|
|
export const sendEmailWithSmtp = async ({ smtpSettings, mailData }: SendMailArgs) => {
|
|
logger.debug("Sending an email with SMTP");
|
|
try {
|
|
const transporter = nodemailer.createTransport({
|
|
...smtpSettings,
|
|
});
|
|
|
|
const response = await transporter.sendMail({
|
|
...mailData,
|
|
});
|
|
|
|
logger.debug("An email has been sent");
|
|
return { response };
|
|
} catch (error) {
|
|
logger.error("Error during sending the email");
|
|
if (error instanceof Error) {
|
|
logger.error(error.message);
|
|
return { errors: [{ message: error.message }] };
|
|
}
|
|
return { errors: [{ message: "SMTP error" }] };
|
|
}
|
|
};
|