This is a community-maintained package and not maintained by the Unsend.

Shout out to QGeeDev for maintaining this package.

Installation

To install the Unsend package, you can use go get:

go get github.com/unsend/unsend-go

Github Repository: Github

Usage

Below is an example of how to use the Unsend package to send an email and retrieve email information.

Environment Variables

export UNSEND_API_KEY="your-api-key"
export UNSEND_API_URL="https://app.unsend.dev" # or your self-hosted URL

Initialize

client, err := unsend.NewClient()

Sending Emails

To send an email you will need to define the payload. After definition, you can use the .SendEmail method to send emails with the payload as a parameter.

func main() {
	godotenv.Load()

	client, err := unsend.NewClient()

	if err != nil {
		fmt.Printf("[ERROR] - %s\n", err.Error())
		os.Exit(1)
	}

	request := &unsend.SendEmailRequest{
		To: []string{"[email protected]"},
		From: "[email protected]",
		Subject: "Unsend test email",
		Text: "hello,\n\nUnsend is the best open source sending platform",
		Html: "<p>hello,</p><p>Unsend is the best open source sending platform</p><p>check out <a href='https://unsend.dev'>unsend.dev</a></p>",
	}

	response, err := client.Emails.SendEmail(context.Background(), *request)

	if err != nil {
		fmt.Printf("[ERROR] - %s\n", err.Error())
		os.Exit(1)
	}

	fmt.Printf("[SUCCESS] - %s\n", response.EmailId)
}

Retrieve Emails using the id

The email will be retrieved using the ID you get after sending the mail.

func main() {
	godotenv.Load()

	client, err := unsend.NewClient()

	getEmailRequest := unsend.GetEmailRequest{
		EmailId: "your-email-id",
	}

	email, err := client.Emails.GetEmail(context.Background(), getEmailRequest)

	if err != nil {
		fmt.Printf("[ERROR] - %s\n", err.Error())
		os.Exit(1)
	}

	fmt.Printf("[SUCCESS] - %s\n", email.Id)
}

More

Checkout more examples in the Github Repository.

It handles emails, domains & contacts APIs.