mirror of
https://github.com/jetzig-framework/jetzig.git
synced 2025-07-01 13:36:08 +00:00

Create mailers with `jetzig generate mailer <name>`. Mailers define default values for email fields (e.g. subject, from address, etc.). Mailers use Zmpl for rendering text/HTML parts. Send an email from a request with `request.mail()`. Call `deliver(.background, .{})` on the return value to use the built-in mail job to send the email asynchronously. Improve query/HTTP request body param parsing - unescape `+` and `%XX` characters.
21 lines
837 B
Zig
21 lines
837 B
Zig
const std = @import("std");
|
|
const jetzig = @import("jetzig");
|
|
|
|
pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View {
|
|
var root = try data.object();
|
|
try root.put("message", data.string("Welcome to Jetzig!"));
|
|
|
|
// Create a new mail using `src/app/mailers/welcome.zig`.
|
|
// HTML and text parts are rendered using Zmpl templates:
|
|
// * `src/app/mailers/welcome/html.zmpl`
|
|
// * `src/app/mailers/welcome/text.zmpl`
|
|
// All mailer templates have access to the same template data as a view template.
|
|
const mail = request.mail("welcome", .{ .to = &.{"hello.dev"} });
|
|
|
|
// Deliver the email asynchronously via a built-in mail Job. Use `.now` to send the email
|
|
// synchronously (i.e. before the request has returned).
|
|
try mail.deliver(.background, .{});
|
|
|
|
return request.render(.ok);
|
|
}
|