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

 SPATIE  

laravel-mailcoach-mailer-go
===========================

spatie.be/open-source

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

 Version   v1      

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

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

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

###  On this page 

1. [ Custom API base URL ](#content-custom-api-base-url)
2. [ Customization ](#content-customization)

Requires Go 1.27 or newer and Laravel Go `go.laravel.com v0.1.0`.

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

Install the package explicitly in `bootstrap/app.go`:

```
import (
    mailcoachmailer "github.com/spatie/laravel-mailcoach-mailer-go"
    laravel "go.laravel.com"
)

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

Installing the Go module alone does not activate it. Registration uses Laravel's native registrar, without a package-tools or Mailcoach SDK dependency.

```
MAIL_MAILER=mailcoach
MAIL_FROM_ADDRESS=hello@example.com
MAIL_FROM_NAME=Your application
MAILCOACH_DOMAIN=your-domain.mailcoach.app
MAILCOACH_API_TOKEN=your-transactional-api-token
```

Registration does not choose the application's default mailer. Set `MAIL_MAILER` to `mailcoach`, or select the mailer with `mail.Use("mailcoach")` for individual sends. Environment defaults are read through the framework, so isolated test environments work too.

Custom API base URL
-----------------------------------------------------------------------------------------------------------------

By default, mails are sent to `https://{domain}/api/transactional-mails/send`. For self-hosted installations, you can send them to another base URL, for example an internal service over HTTP, by setting `MAILCOACH_API_BASE_URL`.

Set it to an absolute HTTP or HTTPS URL, such as `http://mailcoach-service:8080` or `https://internal.example.com/mailcoach`. A port and path prefix are optional. Do not include `/api/transactional-mails/send`, a query string, or a fragment. The transport appends the endpoint itself and removes trailing slashes. Credentials in the URL are rejected.

The override takes precedence over `Domain`, but `Domain` and `Token` remain required, matching PHP. Omitting the override, or setting it to an empty string, keeps the default HTTPS URL based on `Domain`.

Only use HTTP on a trusted network because the token and mail content are sent without TLS encryption.

Customization
-----------------------------------------------------------------------------------------------

Callbacks run after environment defaults. Registration validates the final settings without contacting Mailcoach. Invalid settings stop startup, rather than waiting for the first send.

```
mailcoachmailer.New(func(cfg *mailcoachmailer.Config) {
    cfg.Name = "receipts"
    cfg.Domain = "receipts.mailcoach.app"
    cfg.Token = receiptToken
    cfg.Timeout = 30 * time.Second
})
```

The default timeout is ten seconds and must be positive. There is no timeout environment variable. A domain is a hostname without a scheme, port or path. The API token must be nonempty and contain no control characters.

Set `cfg.Transport` to any native `mail.Transport` to replace delivery entirely. It is used for normal mail, queued mail and the test command. It owns its own validation. Applications may also register a same-name mailer in `Options.Register`, which Laravel gives precedence over a package mailer. Commands can be replaced by registering the same command name. There are no package-owned models, jobs or profile classes.

For additional named mailers, build `NewTransport(Config{Domain: domain, Token: token, Timeout: 10 * time.Second})` and register it with `app.Mailer(name, transport)` in your application. The test command checks the name installed by this package instance, not arbitrary extra mailers.

Unlike the Rust port, this Go port reads `MAILCOACH_API_TOKEN`, matching PHP. It does not read `MAILCOACH_TOKEN`. No credentials are needed to fetch the public module.

 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)
