{"id":34191355,"url":"https://github.com/akfaiz/go-mailgen","last_synced_at":"2026-06-30T17:31:20.402Z","repository":{"id":306191090,"uuid":"1025305444","full_name":"akfaiz/go-mailgen","owner":"akfaiz","description":"Go-Mailgen is a fluent HTML builder for easy, rich email sending.","archived":false,"fork":false,"pushed_at":"2026-05-02T11:58:33.000Z","size":3088,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-02T13:29:29.228Z","etag":null,"topics":["email","email-builder","go","golang","hacktoberfest"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/akfaiz/go-mailgen","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akfaiz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-24T04:11:15.000Z","updated_at":"2026-05-02T12:00:23.000Z","dependencies_parsed_at":"2025-07-25T07:40:03.169Z","dependency_job_id":"d9be6d41-2675-4f1d-899d-49a31c7da87b","html_url":"https://github.com/akfaiz/go-mailgen","commit_stats":null,"previous_names":["ahmadfaizk/go-mailer","ahmadfaizk/go-mailgen","afkdevs/go-mailgen","akfaiz/go-mailgen"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/akfaiz/go-mailgen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akfaiz%2Fgo-mailgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akfaiz%2Fgo-mailgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akfaiz%2Fgo-mailgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akfaiz%2Fgo-mailgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akfaiz","download_url":"https://codeload.github.com/akfaiz/go-mailgen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akfaiz%2Fgo-mailgen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34977666,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-30T02:00:05.919Z","response_time":92,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["email","email-builder","go","golang","hacktoberfest"],"created_at":"2025-12-15T16:01:44.176Z","updated_at":"2026-06-30T17:31:20.392Z","avatar_url":"https://github.com/akfaiz.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go-Mailgen\n\n[![Go](https://github.com/akfaiz/go-mailgen/actions/workflows/ci.yml/badge.svg)](https://github.com/akfaiz/go-mailgen/actions/workflows/ci.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/akfaiz/go-mailgen)](https://goreportcard.com/report/github.com/akfaiz/go-mailgen)\n[![codecov](https://codecov.io/gh/akfaiz/go-mailgen/graph/badge.svg?token=7tbSVRaD4b)](https://codecov.io/gh/akfaiz/go-mailgen)\n[![GoDoc](https://pkg.go.dev/badge/github.com/akfaiz/go-mailgen)](https://pkg.go.dev/github.com/akfaiz/go-mailgen)\n[![Go Version](https://img.shields.io/github/go-mod/go-version/akfaiz/go-mailgen)](https://golang.org/doc/devel/release.html)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n\n\u003cdiv align=\"center\"\u003e\u003cimg src=\"./logo.png\" width=\"150\" alt=\"go-mailgen logo\"/\u003e\u003c/div\u003e\n\n**Go-Mailgen** is a Go library for generating professional HTML emails using a fluent, intuitive API. Simplify email creation with customizable templates and seamless integration into your Go applications. This project is inspired by the [mailgen](https://github.com/eladnava/mailgen) Node.js package, bringing its elegant email generation approach to the Go ecosystem.\n\n## Features\n\n- **Fluent API**: Build emails with a clean, chainable interface.\n- **Inline CSS**: Ensures compatibility across major email clients.\n- **Configurable HTML Transform**: Optionally disable automatic CSS inlining.\n- **Easy Integration**: Works effortlessly with popular Go mail libraries like go-mail.\n- **Chainable Methods**: Add content, actions, and tables in a straightforward manner.\n- **Global Configuration**: Set default base email settings and themes.\n\n## Installation\n\nTo install Go-Mailgen, run the following command:\n\n```bash\ngo get github.com/akfaiz/go-mailgen\n```\n\n## Usage\n\nHere's a simple example of how to use Go-Mailgen to create an email:\n\n```go\npackage main\n\nimport (\n\t\"github.com/akfaiz/go-mailgen\"\n\t\"github.com/wneessen/go-mail\"\n)\n\nfunc main() {\n\t// Initialize SMTP client\n\tmailer, err := mail.NewClient(\"smtp.example.com\",\n\t\tmail.WithPort(587),\n\t\tmail.WithUsername(\"user\"),\n\t\tmail.WithPassword(\"pass\"),\n\t)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Set global configuration (optional)\n\tmailgen.SetDefault(mailgen.New().\n\t\tFrom(\"no-reply@example.com\", \"Go-Mailgen\").\n\t\tProduct(mailgen.Product{\n\t\t\tName: \"Go-Mailgen\",\n\t\t\tLink: \"https://github.com/akfaiz/go-mailgen\",\n\t\t}).\n\t\tTheme(\"default\"),\n\t)\n\n\t// Build the email\nemail := mailgen.New().\n\tSubject(\"Reset Your Password\").\n\tTo(\"johndoe@mail.com\").\n\tUsePremailer(false). // optional: keep raw template HTML (no CSS inlining)\n\tLine(\"Click the button below to reset your password\").\n\tAction(\"Reset your password\", \"https://example.com/reset-password\").\n\tLine(\"If you did not request this, please ignore this email\")\n\tmessage, err := email.Build()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Send the email\n\tmsg := mail.NewMsg()\n\tmsg.Subject(message.Subject())\n\tmsg.From(message.From().String())\n\tmsg.To(message.To()...)\n\tmsg.SetBodyString(mail.TypeTextPlain, message.PlainText())\n\tmsg.SetBodyString(mail.TypeTextHTML, message.HTML())\n\tif err := mailer.DialAndSend(msg); err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\n## More Examples\n\nYou can find more examples in the [examples](examples) directory.\n\n## Documentation\n\nFor detailed documentation, please visit the [Go-Mailgen documentation](https://pkg.go.dev/github.com/akfaiz/go-mailgen).\n\n## Supported Themes\n\nThe following open-source themes are bundled with this package:\n\n- `default` by [Postmark Transactional Email Templates](https://github.com/ActiveCampaign/postmark-templates)\n\n| Welcome | Reset Password | Receipt |\n|---------|----------------|---------|\n| \u003cimg src=\"examples/default/welcome.png\" height=\"200\" /\u003e | \u003cimg src=\"examples/default/reset.png\" height=\"200\" /\u003e | \u003cimg src=\"examples/default/receipt.png\" height=\"200\" /\u003e |\n\n- `plain` by [Postmark Transactional Email Templates](https://github.com/ActiveCampaign/postmark-templates)\n\n| Welcome | Reset Password | Receipt |\n|---------|----------------|---------|\n| \u003cimg src=\"examples/plain/welcome.png\" height=\"200\" /\u003e | \u003cimg src=\"examples/plain/reset.png\" height=\"200\" /\u003e | \u003cimg src=\"examples/plain/receipt.png\" height=\"200\" /\u003e |\n\n### Custom Theme\n\nYou can register your own theme templates and use it via `Theme(...)`:\n\n```go\nimport (\n\thtmltemplate \"html/template\"\n\ttexttemplate \"text/template\"\n\t\"github.com/akfaiz/go-mailgen\"\n)\n\nhtmlTmpl := htmltemplate.Must(htmltemplate.New(\"index.html\").Parse(`\n\t{{define \"index.html\"}}\u003chtml\u003e\u003cbody\u003e{{range .ComponentsHTML}}{{.}}{{end}}\u003c/body\u003e\u003c/html\u003e{{end}}\n\t{{define \"line\"}}\u003cp\u003e{{.Text}}\u003c/p\u003e{{end}}\n\t{{define \"button\"}}\u003ca href=\"{{.Link}}\"\u003e{{.Text}}\u003c/a\u003e{{end}}\n\t{{define \"table\"}}{{end}}\n`))\n\ntextTmpl := texttemplate.Must(texttemplate.New(\"index.txt\").Parse(`\n\t{{define \"index.txt\"}}{{range .ComponentsText}}{{.}}{{\"\\n\"}}{{end}}{{end}}\n`))\n\nmailgen.MustRegisterTheme(\"my-theme\", mailgen.Theme{\n\tHTML:      htmlTmpl,\n\tPlainText: textTmpl, // optional, defaults to built-in plain text template\n})\n\nmessage, err := mailgen.New().\n\tTheme(\"my-theme\").\n\tLine(\"Hello from custom theme\").\n\tBuild()\n```\n\n## RTL Support\n\nTo change default text direction to RTL, you can use the `TextDirection` method:\n\n```go\n// Set the text direction when creating a new email\nemail := mailgen.New().\n\tTextDirection(\"rtl\").\n\tLine(\"هذا هو عنوان البريد الإلكتروني الخاص بك\")\n// or set it globally\nmailgen.SetDefault(mailgen.New().TextDirection(\"rtl\"))\n// Then build the email as usual\nemail := mailgen.New().\n\tLine(\"هذا هو عنوان البريد الإلكتروني الخاص بك\")\n```\n\n## Elements\n\nGo-Mailgen provides several methods to add content to your emails. Here are some of the most commonly used methods:\n\n### Action\n\nTo add an action button to your email, use the `Action` method:\n\n```go\nemail := mailgen.New().\n\tLine(\"To confirm your email address, please click the button below:\").\n\tAction(\"Confirm Email\", \"https://example.com/confirm\")\n\n// To add multiple actions, you can chain the `Action` method:\nemail := mailgen.New().\n\tLine(\"To confirm your email address, please click the buttons below:\").\n\tAction(\"Confirm Email\", \"https://example.com/confirm\").\n\tLine(\"Or you can visit our website:\").\n\tAction(\"Visit Website\", \"https://example.com\")\n```\n\n### Table\n\nTo add a table to your email, use the `Table` method:\n\n```go\nemail := mailgen.New().\n\tLine(\"Your order has been processed successfully.\").\n\tTable(mailgen.Table{\n\t\tData: [][]mailgen.Entry{\n\t\t\t{\n\t\t\t\t{Key: \"Item\", Value: \"Golang\"},\n\t\t\t\t{Key: \"Description\", Value: \"An open-source programming language supported by Google.\"},\n\t\t\t\t{Key: \"Price\", Value: \"$10.99\"},\n\t\t\t},\n\t\t\t{\n\t\t\t\t{Key: \"Item\", Value: \"Mailgen\"},\n\t\t\t\t{Key: \"Description\", Value: \"Programmatically create beautiful e-mails using Golang\"},\n\t\t\t\t{Key: \"Price\", Value: \"$1.99\"},\n\t\t\t},\n\t\t},\n\t\tColumns: mailgen.Columns{\n\t\t\tCustomWidth: map[string]string{\n\t\t\t\t\"Item\":  \"20%\",\n\t\t\t\t\"Price\": \"15%\",\n\t\t\t},\n\t\t\tCustomAlign: map[string]string{\n\t\t\t\t\"Price\": \"right\",\n\t\t\t},\n\t\t},\n\t})\n```\n\nYou can chain the `Table` with other methods to add more content to your email:\n\n```go\nemail := mailgen.New().\n\tLine(\"Your order has been processed successfully.\").\n\tTable(mailgen.Table{\n\t\tData: [][]mailgen.Entry{\n\t\t\t{\n\t\t\t\t{Key: \"Item\", Value: \"Golang\"},\n\t\t\t\t{Key: \"Description\", Value: \"An open-source programming language supported by Google.\"},\n\t\t\t\t{Key: \"Price\", Value: \"$10.99\"},\n\t\t\t},\n\t\t\t{\n\t\t\t\t{Key: \"Item\", Value: \"Mailgen\"},\n\t\t\t\t{Key: \"Description\", Value: \"Programmatically create beautiful e-mails using Golang\"},\n\t\t\t\t{Key: \"Price\", Value: \"$1.99\"},\n\t\t\t},\n\t\t},\n\t\tColumns: mailgen.Columns{\n\t\t\tCustomWidth: map[string]string{\n\t\t\t\t\"Item\":  \"20%\",\n\t\t\t\t\"Price\": \"15%\",\n\t\t\t},\n\t\t\tCustomAlign: map[string]string{\n\t\t\t\t\"Price\": \"right\",\n\t\t\t},\n\t\t},\n\t}).\n\tLine(\"If you have any questions, feel free to contact us.\").\n\tAction(\"Contact Support\", \"https://example.com/contact\").\n\tLine(\"Thank you for your order!\")\n```\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakfaiz%2Fgo-mailgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakfaiz%2Fgo-mailgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakfaiz%2Fgo-mailgen/lists"}