registerEmailService
Register a custom email service provider. EverShop does not send emails by default — you must register an email service in your extension's bootstrap.
Import
import { registerEmailService } from '@evershop/evershop/lib/mail/emailHelper';
Syntax
registerEmailService(service: EmailService): void
interface EmailService {
sendEmail: (args: SendEmailArguments) => Promise<void>;
}
Parameters
service — An object implementing the EmailService interface with a sendEmail method.
The sendEmail method receives:
to(string) — Recipient emailfrom(string) — Sender emailreplyTo(string, optional) — Reply-to address. The contact form email sets it to the visitor's email. Forward it if your provider supports it.subject(string) — Email subjectbody(string) — Compiled HTML bodytemplate(string) — Raw Handlebars templatedata(EmailData) — Template datalocale(string, optional) — Locale used to render the body (currency and date formatting)cc(string[], optional) — CC recipients
Examples
The Resend SDK returns API errors in { error } instead of throwing. Throw it yourself, otherwise a failed send looks successful to EverShop and is never logged.
extensions/resend-email/src/bootstrap.ts
import { registerEmailService } from '@evershop/evershop/lib/mail/emailHelper';
import { Resend } from 'resend';
export default () => {
const resend = new Resend(process.env.RESEND_API_KEY);
registerEmailService({
sendEmail: async (args) => {
const { error } = await resend.emails.send({
from: args.from,
to: args.to,
subject: args.subject,
html: args.body
});
if (error) {
throw new Error(`Resend failed to send the email: ${error.message}`);
}
}
});
};
See Also
- sendEmail — Send an email
- Email System — Full email system guide