|
| 1 | +# Temp Mail Go Client |
| 2 | +[](https://pkg.go.dev/github.com/temp-mail-io/temp-mail-go) |
| 3 | +[](https://github.com/temp-mail-io/temp-mail-go/actions) |
| 4 | + |
| 5 | +The **official Go Client** for [Temp Mail](https://temp-mail.io). This library provides developers a straightforward way to create and manage temporary email addresses, retrieve and delete messages, all via the Temp Mail API. |
| 6 | + |
| 7 | +## Table of Contents |
| 8 | +- [Features](#features) |
| 9 | +- [Installation](#installation) |
| 10 | +- [Quick Start](#quick-start) |
| 11 | +- [Usage Examples](#usage-examples) |
| 12 | + - [Listing Domains](#listing-domains) |
| 13 | + - [Getting Rate Limits](#getting-rate-limits) |
| 14 | + - [Creating Temporary Email](#creating-temporary-email) |
| 15 | + - [Fetching and Deleting Messages](#fetching-and-deleting-messages) |
| 16 | +- [Testing](#testing) |
| 17 | +- [Contributing](#contributing) |
| 18 | +- [License](#license) |
| 19 | +- [Support](#support) |
| 20 | + |
| 21 | +## Features |
| 22 | +- **Create** temporary email addresses with optional domain specifications |
| 23 | +- **Get** current rate limits after API request |
| 24 | +- **Delete** a temporary email along with all its messages |
| 25 | +- **Retrieve** all messages for a specified email |
| 26 | +- **Get** a specific message or download its attachment |
| 27 | + |
| 28 | +## Installation |
| 29 | +To install this Go package, run: |
| 30 | +```bash |
| 31 | +go get github.com/temp-mail-io/temp-mail-go |
| 32 | +``` |
| 33 | + |
| 34 | +## Quick Start |
| 35 | +Below is a simple example to get started: |
| 36 | +```go |
| 37 | +package main |
| 38 | + |
| 39 | +import ( |
| 40 | + "context" |
| 41 | + "fmt" |
| 42 | + "log" |
| 43 | + |
| 44 | + "github.com/temp-mail-io/temp-mail-go" |
| 45 | +) |
| 46 | + |
| 47 | +func main() { |
| 48 | + // Replace with your real API key |
| 49 | + client := tempmail.NewClient("YOUR_API_KEY", nil) |
| 50 | + |
| 51 | + domains, _, err := client.ListDomains(context.Background()) |
| 52 | + if err != nil { |
| 53 | + log.Fatalf("Error listing domains: %v", err) |
| 54 | + } |
| 55 | + |
| 56 | + fmt.Println("Available domains:", domains) |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +## Usage Examples |
| 61 | +### Listing Domains |
| 62 | +```go |
| 63 | +domains, _, err := client.ListDomains(context.Background()) |
| 64 | +if err != nil { |
| 65 | + // handle error |
| 66 | +} |
| 67 | +for _, d := range domains.Domains { |
| 68 | + fmt.Printf("Domain: %s, Type: %s\n", d.Name, d.Type) |
| 69 | +} |
| 70 | +``` |
| 71 | + |
| 72 | +### Getting Rate Limits |
| 73 | +```go |
| 74 | +rate, _, err := client.RateLimit(context.Background()) |
| 75 | +if err != nil { |
| 76 | + // handle error |
| 77 | +} |
| 78 | +fmt.Printf("limit: %d, used: %d, remaining: %d, reset: %s\n", resp.Limit, resp.Used, resp.Remaining, resp.Reset) |
| 79 | +// Output: limit: 1000, used: 0, remaining: 1000, reset: 2025-01-31 23:59:59 +0000 UTC |
| 80 | +``` |
| 81 | + |
| 82 | +You can also get the rate limits from the response headers: |
| 83 | +```go |
| 84 | +email, resp, err := client.CreateEmail(context.Background(), tempmail.CreateEmailOptions{}) |
| 85 | +if err != nil { |
| 86 | + // handle error |
| 87 | +} |
| 88 | +fmt.Printf("Rate limit: %d\n", resp.Rate.Limit) |
| 89 | +``` |
| 90 | + |
| 91 | +### Creating Temporary Email |
| 92 | +```go |
| 93 | +email, _, err := client.CreateEmail(context.Background(), tempmail.CreateEmailOptions{ |
| 94 | + Domain: "example.com", |
| 95 | +}) |
| 96 | +if err != nil { |
| 97 | + // handle error |
| 98 | +} |
| 99 | +fmt.Printf("Created temporary email: %s (TTL: %s)\n", email.Email, email.TTL) |
| 100 | +``` |
| 101 | + |
| 102 | +### Fetching and Deleting Messages |
| 103 | +```go |
| 104 | +messages, _, err := client. ListEmailMessages(context. Background(), "[email protected]") |
| 105 | +if err != nil { |
| 106 | + // handle error |
| 107 | +} |
| 108 | +fmt.Printf("Fetched %d messages.\n", len(messages)) |
| 109 | + |
| 110 | +// Deleting a specific message |
| 111 | +_, err = client.DeleteMessage(context.Background(), messages[0].ID) |
| 112 | +if err != nil { |
| 113 | + // handle error |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +## Testing |
| 118 | +We use the Go testing framework with both unit tests and optional integration tests. |
| 119 | + |
| 120 | +Run tests locally: |
| 121 | +```bash |
| 122 | +go test ./... -v |
| 123 | +``` |
| 124 | + |
| 125 | +In CI, the tests are automatically executed via [GitHub Actions](https://github.com/temp-mail-io/temp-mail-go/actions). |
| 126 | + |
| 127 | +## Contributing |
| 128 | +We welcome and appreciate contributions! Please see our CONTRIBUTING.md for guidelines on how to open issues, submit pull requests, and follow our coding standards. |
| 129 | + |
| 130 | +## License |
| 131 | +This project is licensed under the MIT License. |
| 132 | + |
| 133 | +## Support |
| 134 | +If you encounter any issues, please open [an issue](https://github.com/temp-mail-io/temp-mail-go/issues) on GitHub. We are happy to help you! |
0 commit comments