hermes golang email 模版包

hermes 提供了灵活的基于html 的email发送模版支持,使用简单,而且也包含了灵活的主题支持

参考使用

  • 项目准备
    main.go
 
package main
 
import (
    "io/ioutil"
    "log"
 
    "github.com/matcornic/hermes/v2"
)
 
func main() {
    h := hermes.Hermes{
        Product: hermes.Product{
            Name: "Hermes",
            Link: "https://example-hermes.com/",
            Logo: "https://github.com/matcornic/hermes/blob/master/examples/gopher.png?raw=true",
        },
    }
    email := hermes.Email{
        Body: hermes.Body{
            Name: "Jon Snow",
            Intros: []string{
                "Welcome to Hermes! We're very excited to have you on board.",
            },
            Actions: []hermes.Action{
                {
                    Instructions: "To get started with Hermes, please click here:",
                    Button: hermes.Button{
                        Color: "#22BC66", // Optional action button color
                        Text:  "账户确认",
                        Link:  "https://hermes-example.com/confirm?token=d9729feb74992cc3482b350163a1a010",
                    },
                },
            },
            Outros: []string{
                "Need help, or have questions? Just reply to this email, we'd love to help.",
            },
        },
    }
 
    // Generate an HTML email with the provided contents (for modern clients)
    emailBody, err := h.GenerateHTML(email)
    if err != nil {
        panic(err) // Tip: Handle error with something else than a panic ;)
    }
 
    // Generate the plaintext version of the e-mail (for clients that do not support xHTML)
    emailText, err := h.GeneratePlainText(email)
    if err != nil {
        panic(err) // Tip: Handle error with something else than a panic ;)
    }
 
    log.Println(emailText)
    // Optionally, preview the generated HTML e-mail by writing it to a local file
    err = ioutil.WriteFile("preview.html", []byte(emailBody), 0644)
    if err != nil {
        panic(err) // Tip: Handle error with something else than a panic ;)
    }
}
 
  • 效果

 

 

说明

从效果来看,还是一个很不错的选择,至少简单,而且比较专业

参考资料

https://github.com/matcornic/hermes

posted on   荣锋亮  阅读(219)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2020-07-02 crystal-lang 学习二 macos openssl 问题
2020-07-02 几个不错的golang 应用升级以及平滑启动包
2020-07-02 crystal-lang 学习一 安装基本环境
2019-07-02 nexus 3.17.0 简单试用
2019-07-02 nexus 3.17.0 简单说明
2019-07-02 Building a Service Mesh with HAProxy and Consul
2019-07-02 Using HAProxy as an API Gateway, Part 3 [Health Checks]

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示