Open Source Go Library to Send Responsive Email Messages
Open Source Free Go API allows to Create and Send Responsive HTML Email Messages with Attachments using Email Templates & Tables inside Go Apps.
What is Hermes ?
Hermes is a free pure GO API to generate clean and responsive HTML email messages. The API is specifically designed to send transactional emails including welcome emails, reset password e-mails, receipt emails, and more. This open-source Go API provides both responsive HTML email as well as associated plain text. The API provides a bunch of templates to send email messages, these pre-design HTML templates help you send beautifully designed emails directly from the Go development environment.
The API is enriched by providing interactive email messages. You can send email messages with a welcome button & an invite code, you can send receipts, reset password emails, and normal maintenance emails - for that the API provides open-source default & flat email templates. The API provides RTL support, allows language customizations, allows injecting tables and you can inject key-value pairs of data by using the Dictionary object.
Getting Started with Hermes
The recommended way to add hermes into your project is by using GitHub. Please use the following command for a smooth installation.
Install Hermes via GitHub
go get -u github.com/matcornic/hermes/v2
Generate Responsive Email via Free GO API
The open-source Go API Hermes allows sending responsive HTML emails easily and efficiently. Hermes API divides the email design into smaller sections. You can set Names and Intros in the Body section of the email. In order to set perform an operation within an email like activating the user or for any conformation, the API allows using Action. You can insert buttons in the actions as per your needs and set color, text, and link for the button. Once you have your content ready, you can convert it to HTML using GenerateHtml() method provided by the API and send it to the destination.The following simple example demonstrates, how software developers can send an email message inside Go applications.
How to Send Responsive Email Messages using Go API?
package main
import (
"github.com/matcornic/hermes/v2"
"net/smtp"
)
func main() {
// Initialize Hermes with SMTP credentials
h := hermes.Hermes{
Product: hermes.Product{
Name: "Hermes",
Link: "https://github.com/matcornic/hermes",
},
}
// Create a responsive email message
email := hermes.Email{
Body: hermes.Body{
Name: "John",
Intros: []string{"Welcome to Hermes!"},
Actions: []hermes.Action{
{
Instructions: "To get started with Hermes, click the button below.",
Button: hermes.Button{
Text: "Get Started",
Link: "https://github.com/matcornic/hermes",
},
},
},
Outros: []string{"Thanks for using Hermes."},
},
}
// Generate and send the email
emailContent, err := h.GenerateHTML(email)
if err != nil {
panic(err)
}
// Send the email using SMTP
auth := smtp.PlainAuth("", "your_username", "your_password", "smtp.example.com")
err = smtp.SendMail("smtp.example.com:587", auth, "sender@example.com", []string{"recipient@example.com"}, []byte(emailContent))
if err != nil {
panic(err)
}
}
Use Templates to Send Emails via Open Source API
This free GO API allows using templates to send emails. There are two basic types of email templates that you can use to send messages - default & Flat. The default template is backed by the postmark transactional email templates. They are solid email templates that can render into tons of email clients. Furthermore, these templates are mobile-friendly, content ready, and are visually beautiful across all major email clients. The flat theme is just a slightly modified version of postmark transactional email templates.
How to Utilize Templates for Sending Email Content using Go API?
package main
import (
"github.com/matcornic/hermes/v2"
"net/smtp"
)
func main() {
// Initialize Hermes with SMTP credentials
h := hermes.Hermes{
Product: hermes.Product{
Name: "Hermes",
Link: "https://github.com/matcornic/hermes",
},
}
// Create an email template
email := hermes.Email{
Body: hermes.Body{
Name: "John",
Intros: []string{"Hello {{ .Name }},", "This is a template-based email."},
Actions: []hermes.Action{
{
Instructions: "Click the button below to learn more.",
Button: hermes.Button{
Text: "Learn More",
Link: "https://github.com/matcornic/hermes",
},
},
},
Outros: []string{"Thank you for your attention."},
},
}
// Generate and send the email
emailContent, err := h.GenerateHTML(email)
if err != nil {
panic(err)
}
// Send the email using SMTP
auth := smtp.PlainAuth("", "your_username", "your_password", "smtp.example.com")
err = smtp.SendMail("smtp.example.com:587", auth, "sender@example.com", []string{"recipient@example.com"}, []byte(emailContent))
if err != nil {
panic(err)
}
}
Insert Tables in Emails via Free Go API
This open-source Go API allows injecting tables into your email messages. You can insert tables inside the Body section of the email. The API provides a Data section to insert data in the table. By using the Key and Value pair you can add column and column values in the table. In order to customize the table columns, you can style the columns using CustomWidth, CustomAlignment, and more. Here is a powerful example that shows how software developers can insert tables inside their email messages using Go API.
How to Insert a Table into an E-mail Message using Go Code?
from hermes import Hermes
email := hermes.Email{
Body: hermes.Body{
Table: hermes.Table{
Data: [][]hermes.Entry{
// List of rows
{
// Key is the column name, Value is the cell value
// First object defines what columns will be displayed
{Key: "Item", Value: "Golang"},
{Key: "Description", Value: "Open source programming language that makes it easy to build simple, reliable, and efficient software"},
{Key: "Price", Value: "$10.99"},
},
{
{Key: "Item", Value: "Hermes"},
{Key: "Description", Value: "Programmatically create beautiful e-mails using Golang."},
{Key: "Price", Value: "$1.99"},
},
},
Columns: hermes.Columns{
// Custom style for each rows
CustomWidth: map[string]string{
"Item": "20%",
"Price": "15%",
},
CustomAlignment: map[string]string{
"Price": "right",
},
},
},
},
}