• 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

  • 相关阅读:
    Hbase常用Shell命令
    Hbase的安装与基本操作
    Unity3d 游戏设计(一)井字棋
    Unity3d 二、离散仿真引擎基础
    Unity3D 一、游戏
    String StringBuffer StringBulider
    Java日志记录log4j最简明教程
    使用PinYin4j.jar将汉字转换为拼音
    线性素数筛
    求一个数的约数个数 d(n)
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/14965267.html
Copyright © 2020-2023  润新知