Installation and setup | laravel-mailcoach-sdk-go | Spatie       

 SPATIE  

laravel-mailcoach-sdk-go
========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-mailcoach-sdk-go](https://spatie.be/docs/laravel-mailcoach-sdk-go/v1)  Installation and setup

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-mailcoach-sdk-go/v1) 

  Installation and setup    
- [ Introduction ](https://spatie.be/docs/laravel-mailcoach-sdk-go/v1/introduction)
- [ Installation and setup ](https://spatie.be/docs/laravel-mailcoach-sdk-go/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/laravel-mailcoach-sdk-go/v1/usage)
- [ Testing ](https://spatie.be/docs/laravel-mailcoach-sdk-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/laravel-mailcoach-sdk-go/v1/releasing)
- [ Changelog ](https://spatie.be/docs/laravel-mailcoach-sdk-go/v1/changelog)
- [ Support us ](https://spatie.be/docs/laravel-mailcoach-sdk-go/v1/support-us)

 Installation and setup
======================

###  On this page 

1. [ Plain Go ](#content-plain-go)
2. [ Laravel Go ](#content-laravel-go)

Requires Go 1.27 or newer. You can install the package with:

```
go get github.com/spatie/laravel-mailcoach-sdk-go@v0.1.0
```

You'll find both the API token and endpoint on Mailcoach's API tokens screen in the Mailcoach settings.

Plain Go
--------------------------------------------------------------------------------

```
import "github.com/spatie/laravel-mailcoach-sdk-go"

client, err := mailcoach.New(apiToken, endpoint)
if err != nil {
    return err
}
```

The endpoint may be the installation URL or its `/api` URL, including a self-hosted subdirectory. It must be HTTP or HTTPS, without embedded credentials, a query or fragment. The client normalizes it to a trailing `/api/`. No request is made at construction.

Use `mailcoach.WithTimeout(45*time.Second)` to change the total timeout. Zero and negative timeouts are rejected. Use `mailcoach.WithHTTPClient(httpClient)` to inject a custom transport or connection pool. The HTTP client is copied, must have a positive timeout, and its redirect policy is replaced with a no-redirect policy. Set `WithTimeout` after `WithHTTPClient` to override the supplied timeout.

The core imports only the standard library. Plain Go applications do not compile or import Laravel.

Laravel Go
--------------------------------------------------------------------------------------

Requires `go.laravel.com v0.1.0`. Add the integration explicitly in `bootstrap/app.go`:

```
import (
    mailcoachlaravel "github.com/spatie/laravel-mailcoach-sdk-go/laravel"
    laravel "go.laravel.com"
)

func Options() laravel.Options {
    return laravel.Options{
        Packages: []laravel.Package{mailcoachlaravel.New()},
    }
}
```

In your `.env` file add:

```
MAILCOACH_API_TOKEN=your-api-token
MAILCOACH_API_ENDPOINT=https://your-installation.example/api
```

No config publishing, database columns or migrations are required. Installing the module alone does not activate the integration. Missing credentials stop application startup, rather than failing on the first API call.

Configuration callbacks run after environment defaults:

```
mailcoachlaravel.New(func(cfg *mailcoachlaravel.Config) {
    cfg.APIToken = token
    cfg.Endpoint = endpoint
    cfg.Timeout = 45 * time.Second
})
```

The default transport uses the application's HTTP client, including its fakes and tracing. API errors have the same `mailcoach.APIError` type in plain Go and Laravel. Set `cfg.HTTPClient` to use a standard HTTP client instead. `cfg.Timeout` controls the final timeout in either case.

To replace the entire service, provide an already configured client:

```
mailcoachlaravel.New(func(cfg *mailcoachlaravel.Config) {
    cfg.Client = customClient
})
```

`cfg.Client` takes precedence over all other settings. Retrieve it with `mailcoachlaravel.From(r)` in a handler, or `mailcoachlaravel.From(ctx)` in a job, listener or command. Configuration belongs to the application, so isolated test applications do not share it.

Laravel Go v0.1.0 returns the first matching registered service. Registering another client later is not a reliable override. Use `cfg.Client` instead.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
