Installation and setup | laravel-newsletter-rust | Spatie       

 SPATIE  

  Laravel Newsletter 
=====================

spatie.be/open-source

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

 Version   v1      

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

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

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

This package requires Rust 1.99+ and Laravel Rust. The supported Laravel range is `>=0.1.0, <1.0`; package-tools uses `>=0.1.5, <1.0`. Both are required dependencies. No database or frontend features are enabled by the library.

You can install this package using Cargo:

```
cargo add spatie-laravel-newsletter
```

Register the service provider in `src/app.rs`:

```
Application::configure()
    .with_providers(|providers| {
        providers.add(spatie_newsletter::service_provider());
    });
```

The provider registers environment-backed defaults and an injectable `Newsletter` singleton through `spatie-laravel-package-tools`. Application configuration always runs after package defaults. The singleton reads the final configuration when first resolved.

Set these values in `.env`:

```
NEWSLETTER_DRIVER=mailcoach
NEWSLETTER_API_KEY=your-api-key
NEWSLETTER_ENDPOINT=https://your-mailcoach.app
NEWSLETTER_LIST_ID=your-email-list-uuid
```

`NEWSLETTER_DEFAULT_LIST_NAME` defaults to `subscribers`. `NEWSLETTER_TIMEOUT` is a positive integer in seconds and defaults to `30`. Invalid numeric environment values stop startup. Missing credentials and invalid driver settings are reported when the service is first resolved, not while registering the provider.

### Lists

You can use any list names and add as many lists as you want. Each name maps to a provider identifier:

```
use spatie_newsletter::{Config, NewsletterList, service_provider};

let app = Application::configure()
    .with_providers(|providers| {
        providers.add(service_provider());
    })
    .with_config(|config, _| {
        let newsletter = config.section_mut::<Config>();
        newsletter.lists.insert("authors".into(), NewsletterList::new("author-list-id"));
        newsletter.default_list_name = "authors".into();
    })
    .create();
```

Select one with `newsletter.list("authors")`. This returns a cheap clone and does not change the singleton's default list. An empty name uses `default_list_name`. Unknown list names and blank list identifiers return errors. `NewsletterList.properties` and `DriverArguments.options` retain arbitrary settings for custom drivers.

### Using Mailcoach

Provide the API key, endpoint, and email list UUID. You'll find the API key and endpoint in the [Mailcoach](https://mailcoach.app) settings screen. The list UUID is on the settings screen of an email list.

The Mailcoach SDK is included. The driver uses `Mailcoach::with_laravel`, so Laravel's HTTP fakes intercept every request. Confirmation remains a server decision; the driver does not silently bypass double opt-in. Use `subscribe_with_options` to explicitly pass API fields such as `skip_confirmation`.

### Using Mailchimp

Set `NEWSLETTER_DRIVER=mailchimp`. Provide the API key and list ID from the Mailchimp UI. Leave `NEWSLETTER_ENDPOINT` unset; the driver derives the API data center from the key's suffix, for example `-us7`. You can supply an explicit API base when needed.

Use merge field names such as `FNAME` and `LNAME`. `subscribe_pending` requests double opt-in. Additional options can specify interests, email type, or status. Mailchimp's subscription options override defaults, including fields supplied by the method.

### Using MailerLite

Set `NEWSLETTER_DRIVER=mailerlite`. Provide the API key and group ID from your MailerLite dashboard under Integrations &gt; API. Leave `NEWSLETTER_ENDPOINT` unset to use `https://connect.mailerlite.com/api`.

Use subscriber fields such as `name` and `last_name`. Both subscribe methods use MailerLite's create-or-update endpoint. Additional options override the default email, groups, and fields.

### Using Brevo

Set `NEWSLETTER_DRIVER=brevo`. The API key is in the 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 `.env` are supported. Leave the endpoint unset to use `https://api.brevo.com/v3`.

Pass existing Brevo contact attributes using their uppercase names, for example `FIRSTNAME`. `subscribe` creates a contact and fails if it already exists; `subscribe_or_update` also updates existing contacts. Options such as `smsBlacklisted` are forwarded, but cannot override the email, attributes, selected list, or create/update mode. Existing email blocklisting is not automatically cleared.

### Transport customization

Set `Config.driver_arguments.timeout` to a `Duration`. For Mailchimp, MailerLite, and Brevo, `driver_arguments.request` can replace the authenticated `PendingRequest` template entirely. Supply authentication, headers, timeout, and transport policy on your replacement; internal requests still use the configured endpoint. This supports Laravel client hooks, proxies, custom certificates, and application-owned clients.

For Mailcoach, construct a `MailcoachDriver::with_api(config, api)` with your SDK client and set `Config.custom_driver`. Use the SDK's Laravel transport if you want Laravel HTTP fakes and tracing.

Built-in transports disable redirects and automatic retries to avoid forwarding credentials or repeating mutations. A custom transport owns those decisions. Do not log raw requests or response bodies; Brevo's custom `api-key` header and subscriber data can contain secrets or personal data.

### Disabling API calls

Set `NEWSLETTER_DRIVER=null` or `NEWSLETTER_DRIVER=log` to prevent API calls. The log driver writes operation names at debug level without email addresses or attributes. Mutations succeed without changing anything; member lookups return `None`, and membership checks return `false`. Neither mode requires credentials or list configuration.

 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)
