Welcome to the unofficial Mailtrap Go Client repository.
This client allows you to quickly and easily integrate your Go application with v2.0 of the Mailtrap API.
To get the most out of this official Mailtrap.io Go SDK:
The Mailtrap Go client provides comprehensive access to the Mailtrap API v2.0, including:
- Send an email (Transactional and Bulk streams)
- Send an email with a template
- Send emails with attachments
The following few simple steps will bring Mailtrap API functionality into your Go project.
The Mailtrap Go client packages are available through GitHub Packages.
Add Mailtrap package:
go get -u github.com/bakbuz/mailtrap-goNow you can inject EmailClient instance in any application service and use it to make API calls.
// client
var client emails.EmailClient = emails.NewEmailClient("<API_KEY>")
// request
req := request.Create().
WithFrom("john.doe@demomailtrap.com", "John Doe").
WithTo("hero.bill@galaxy.net", "").
WithSubject("Invitation to Earth").
WithTextBody("Dear Bill,\n\nIt will be a great pleasure to see you on our blue planet next weekend.\n\nBest regards, John.")
// response
res, err := client.Send(context.Background(), req)
if err != nil {
log.Fatal(err)
}
fmt.Println("response: ", res.Success)
if res.Success {
fmt.Println("message Ids: ", res.MessageIds)
} else {
fmt.Println("error messages: ", res.ErrorData)
}