FetchWeb Email is a simple SMTP Email API written in Go with no dependencies outside of the Go standard library.
package main
import (
"encoding/json"
"io/ioutil"
email "github.com/FetchWeb/Email"
)
func main() {
// Initailise credentials & data objects.
creds := &email.Credentials{
Address: "<Sending email address>",
Hostname: "<Hostname of SMTP Server>",
Name: "<Name appearing on email>",
Port: "<Port email being sent on>",
Password "<Password to email account>"
}
data := &email.Data{
Attachments: make(map[string]*email.Attachment)
}
// Add email body.
data.Body = "Hello world from FetchWeb Mail!"
// Add attachment from file.
if err := data.AddAttachmentFromFile("<Attachment directory>", false); err != nil {
panic(err)
}
// Send email.
if err := email.Send(creds, data); err != nil {
panic(err)
}
}