Zum Inhalt springen

Goravel v1.17 Preview: Sending emails supports rendering with view templates

Goravel – A high-performance, full-featured, and easily extensible Golang devleopment framework. Its coding style is consistent with Laravel, makeing it the top choice for Phpers during the transition.

New feature of the Mail module: It supports directly using view templates to render emial content, enabling developers to create beautiful emails more conveniently. It has been merged into the master branch, thanks to the core developer @kkumar-gcc for the contribution.

Core Features

  1. Configurable template engine: Supports switching between different template engines through configration.
  2. Built-in caching mechanism: The template only needs to be parsed once, and subsequent usage directly reads from the cache.
  3. Thread safey: Supports concurrent use in multiple goroutines.
  4. Global registry: The template engines will be cached globally to avoid repeated creation.

Usage guide

Create an email template:

<!-- resources/views/mail/welcome.tmpl -->
<h1>Welcome {{.Name}}!</h1>
<p>Thanks for joining {{.AppName}}。</p>

Send the email template:

facades.Mail().
    To([]string{"user@example.com"}).
    Subject("Welcome").
    Content(mail.Content{
        View: "welcome.tmpl",
        With: map[string]any{
            "Name": "Tom",
            "AppName": "Goravel",
        },
    }).
    Send()

See details in PR: https://github.com/goravel/framework/pull/1145

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert