# README
SMTP2GO API
Go wrapper around the SMTP2GO /email/send API endpoint.
Installation
go get github.com/smtp2go-oss/smtp2go-go
Add the import in your source file
import "github.com/smtp2go-oss/smtp2go-go"
Usage
Sign up for a free account here and once logged in navigate
to the Settings -> Api Keys
page, create a new API key and make sure the /email/send
endpoint
is enabled:
Once you have an API key you need to export it into the environment where your Go application is going to be executed, this can be done on the terminal like so:
`$ export SMTP2GO_API_KEY="<your_API_key>"`
Or alternatively you can set it in code via
import "os"
os.Setenv("SMTP2GO_API_KEY", "<your_API_key>")
Then sending mail is as simple as:
package main
import (
"fmt"
"github.com/smtp2go-oss/smtp2go-go"
)
func main() {
email := smtp2go.Email{
From: "Matt <[email protected]>",
To: []string{
"Dave <[email protected]>",
},
Subject: "Trying out SMTP2GO",
TextBody: "Test Message",
HtmlBody: "<h1>Test Message</h1>",
}
res, err := smtp2go.Send(&email)
if err != nil {
fmt.Printf("An Error Occurred: %s", err)
}
fmt.Printf("Sent Successfully: %s", res)
}
You can also send Asynchronously:
package main
import (
"fmt"
"github.com/smtp2go-oss/smtp2go-go"
)
func main() {
email := smtp2go.Email{
From: "Matt <[email protected]>",
To: []string{
"Dave <[email protected]>",
},
Subject: "Trying out SMTP2GO",
TextBody: "Test Message",
HtmlBody: "<h1>Test Message</h1>",
}
var c chan *smtp2go.SendAsyncResult = smtp2go.SendAsync(&email)
res := <-c
if res.Error != nil {
fmt.Printf("An Error Occurred: %s", res.Error)
}
fmt.Printf("Sent Successfully: %s", res.Result)
}
Development
Clone repo. Run tests with go test
.
Contributing
Bug reports and pull requests are welcome on GitHub here
License
The package is available as open source under the terms of the MIT License.