@adonisjs/mail
Version:
Mail provider for adonis framework and has support for all common mailing services to send emails
78 lines (77 loc) • 2.12 kB
JavaScript
import {
MailManager,
Mailer,
Message
} from "../chunk-ZEBABAZZ.js";
import "../chunk-F3J2XAU5.js";
import "../chunk-TDHID2NL.js";
import "../chunk-ASVKPASJ.js";
import "../chunk-3EFD4MAA.js";
import "../chunk-CRXUSCKP.js";
import "../chunk-ZF2M7BIF.js";
import {
__name
} from "../chunk-XE4OXN2W.js";
// providers/mail_provider.ts
import { configProvider } from "@adonisjs/core";
import { RuntimeException } from "@poppinss/utils";
var MailProvider = class {
static {
__name(this, "MailProvider");
}
app;
constructor(app) {
this.app = app;
}
/**
* Defines the template engine on the message class to
* render templates
*/
async defineTemplateEngine() {
if (this.app.usingEdgeJS) {
const edge = await import("edge.js");
Message.templateEngine = {
render(templatePath, helpers, data) {
return edge.default.share(helpers).render(templatePath, data);
}
};
const { mailPluginEdge } = await import("../src/plugins/edge.js");
edge.default.use(mailPluginEdge);
}
}
/**
* Registering bindings to container
*/
register() {
this.app.container.singleton("mail.manager", async (resolver) => {
const emitter = await resolver.make("emitter");
const mailConfigProvider = await this.app.config.get("mail");
const config = await configProvider.resolve(this.app, mailConfigProvider);
if (!config) {
throw new RuntimeException('Invalid "config/mail.ts" file. Make sure you are using the "defineConfig" method');
}
return new MailManager(emitter, config);
});
this.app.container.bind(Mailer, async (resolver) => {
const mailManager = await resolver.make("mail.manager");
return mailManager.use();
});
}
/**
* Invoked automatically when the app is booting
*/
async boot() {
await this.defineTemplateEngine();
}
/**
* Cleanup hook
*/
async shutdown() {
const mail = await this.app.container.make("mail.manager");
await mail.closeAll();
}
};
export {
MailProvider as default
};
//# sourceMappingURL=mail_provider.js.map