Installation and setup | laravel-newsletter-go | Spatie       

 SPATIE  

  Laravel Newsletter Go 
========================

spatie.be/open-source

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

 Version   v1      

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

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

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

###  On this page 

1. [ Using Mailcoach ](#content-using-mailcoach)
2. [ Using MailChimp ](#content-using-mailchimp)
3. [ Using MailerLite ](#content-using-mailerlite)
4. [ Using Brevo ](#content-using-brevo)
5. [ Null and logging drivers ](#content-null-and-logging-drivers)

This package requires Go 1.27 or newer and Laravel Go `go.laravel.com v0.1.0`.

You can install this package using:

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

Add the package to `bootstrap/app.go`. Installing the module alone does not activate it.

```
import (
    "github.com/spatie/laravel-newsletter-go"
    laravel "go.laravel.com"
)

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

The package reads these values from the application's environment:

```
NEWSLETTER_DRIVER=mailcoach
NEWSLETTER_API_KEY=your-api-key
NEWSLETTER_ENDPOINT=https://your-mailcoach-domain/api
NEWSLETTER_LIST_ID=your-email-list-uuid
NEWSLETTER_DEFAULT_LIST_NAME=subscribers
```

The default driver is `mailcoach` and the default list name is `subscribers`. Explicit configuration callbacks run after the environment defaults. There is no config file to publish.

```
newsletter.New(func(cfg *newsletter.Config) {
    cfg.DefaultList = "subscribers"
    cfg.Lists = map[string]newsletter.List{
        "subscribers": {ID: "your-list-id"},
        "customers": {ID: "another-list-id"},
    }
})
```

You can set list names to any string you want and add as many lists as you want. Each list also has a `Properties` map for custom metadata. Invalid list names and missing IDs return errors before sending a request.

Using Mailcoach
-----------------------------------------------------------------------------------------------------

To let this package work with Mailcoach, set `NEWSLETTER_DRIVER=mailcoach`. No additional SDK is needed.

Next, you must provide values for the API key, endpoint and list ID. You'll find the API key and endpoint in the [Mailcoach](https://mailcoach.app) settings screen. The list ID must be the UUID of an email list on Mailcoach. You'll find this value on the settings screen of an email list.

The endpoint is the full API base URL, including `/api` when your installation uses it. Extra properties are sent as subscriber attributes. The options map is ignored, matching PHP.

`SubscribeOrUpdate` first tries to create the subscriber. A 409 or 422 response triggers a lookup and update of the existing subscriber. Unlike the PHP package, authentication, transport and server failures do not trigger a second mutation attempt.

Using MailChimp
-----------------------------------------------------------------------------------------------------

Set `NEWSLETTER_DRIVER=mailchimp`. You must provide values for the API key and list ID. You'll find these values in the MailChimp UI.

Leave `NEWSLETTER_ENDPOINT` unset. The datacenter is derived from the API key's suffix, such as `us7` in `your-key-us7`. You can provide an explicit API base URL when needed.

Properties become merge fields. The options map can override the default `email_address`, `status`, `email_type` and `merge_fields`, and can supply interests or marketing permissions.

Using MailerLite
--------------------------------------------------------------------------------------------------------

Set `NEWSLETTER_DRIVER=mailerlite`. You need to provide the API key and group ID. These can be found in your MailerLite Dashboard under Integrations &gt; API.

The endpoint defaults to `https://connect.mailerlite.com/api`. No additional SDK is needed. Properties become subscriber fields. Options can override fields, groups and email, matching PHP.

`Subscribe` and `SubscribeOrUpdate` both use MailerLite's create-or-update endpoint. Member lookups are scoped to the selected group.

Using Brevo
-----------------------------------------------------------------------------------------

Set `NEWSLETTER_DRIVER=brevo`. The API key can be found in your Brevo dashboard under SMTP &amp; API &gt; API Keys. Set `NEWSLETTER_LIST_ID` to the positive integer ID of a contact list under Contacts &gt; Lists. Numeric strings from your environment are supported.

The endpoint defaults to `https://api.brevo.com/v3`. No additional SDK is needed. Set `Config.API` to customize HTTP settings such as timeouts or transport.

Pass existing Brevo contact attributes, using their uppercase names:

```
member, err := newsletter.From(ctx).SubscribeOrUpdate(ctx, "jane@example.com", newsletter.Subscription{
    Properties: map[string]any{"FIRSTNAME": "Jane"},
    List: "subscribers",
})
```

`Subscribe` creates a contact and fails if it already exists. `SubscribeOrUpdate` also updates existing contacts. `Subscription.Options` accepts additional Brevo create-contact fields, such as `smsBlacklisted`. It cannot override the email, attributes, selected list or create/update mode supplied by the method. Existing email blocklisting is not automatically cleared.

`GetMember`, `HasMember` and `IsSubscribed` use the selected list, or the default list when omitted. `IsSubscribed` also checks email blocklisting and list-specific unsubscriptions.

`Unsubscribe` removes the contact from only the selected or default list. It does not globally blocklist or delete the contact. **`Delete` permanently deletes the contact across the Brevo account, regardless of the list name.** Use `Unsubscribe` to remove only list membership.

Failed API requests return errors. Subscribe, update and unsubscribe return the refreshed contact. If that follow-up lookup fails, they return an error even though the preceding mutation may already have succeeded.

Null and logging drivers
--------------------------------------------------------------------------------------------------------------------------------

Use `NEWSLETTER_DRIVER=null` to prevent API calls. Use `log` to also record method calls at debug level through `slog`. Both drivers return empty results and no errors. Membership checks return false because no real member was looked up. An explicitly empty driver name also selects the null driver.

 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)
