---
title: Go
description: "The Unsend Go package lets you interact with the Unsend API to send and manage emails as well as domains. This is a quick guide on using the package to send emails and retrieve email information."
icon: golang
---

<Warning>
  This is a community-maintained package and not maintained by the Unsend.
</Warning>

**Shout out to [QGeeDev](https://bsky.app/profile/qgdev.co.uk) for maintaining this package.**

## Installation

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

```bash
go get github.com/QGeeDev/unsend-go
```

## Related Links

GitHub Repository: [GitHub](https://github.com/QGeeDev/unsend-go)

## Usage

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

### Environment Variables

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

### Initialize

```go
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.

```go
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{"youremail@gmail.com"},
		From: "hello@yourdomain.com",
		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.

```go
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](https://github.com/QGeeDev/unsend-go/tree/main/examples).

It handles `emails`, `domains` & `contacts` APIs.
