Custom drivers | 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)  Custom drivers

 Version   v1      

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

  Custom drivers    
- [ 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)

 Custom drivers
==============

Implement the async `Driver` trait to integrate another email service. It exposes subscription, update, unsubscribe, delete, lookup, and subscription-state methods. `has_member` has a default implementation using `get_member`.

Use `#[async_trait::async_trait]` on your implementation. Methods return `Result`; a missing member is `Ok(None)`, not an error. The list argument is empty when the caller hasn't selected a list, so your driver can preserve the distinction between a default and an explicit list. `Config::find_list` resolves either form.

Construct your driver in `with_config` using the final settings and store it in `Config.custom_driver`, or replace the whole service in `with_services`. For example, an application can disable subscription calls with the included null driver:

```
use spatie_newsletter::{Newsletter, NullDriver, service_provider};

let app = Application::configure()
    .with_providers(|providers| {
        providers.add(service_provider());
    })
    .with_services(|services| {
        services.instance(Newsletter::new(NullDriver::default()));
    })
    .create();
```

For configuration-based replacement:

```
use std::sync::Arc;
use spatie_newsletter::{Config, NullDriver, service_provider};

let app = Application::configure()
    .with_providers(|providers| {
        providers.add(service_provider());
    })
    .with_config(|config, _| {
        let newsletter = config.section_mut::<Config>();
        newsletter.custom_driver = Some(Arc::new(NullDriver::default()));
    })
    .create();
```

Replace `NullDriver` with your own implementation. A custom driver can accept a cloned `Config`, an application-owned client, or any other dependency in its constructor. Arbitrary per-list properties live in `NewsletterList.properties`; driver-wide properties live in `DriverArguments.options`. No subclassing or global mutable registry is required.

Use `Driver::api` or `Driver::mailcoach` when your driver can expose those clients; their defaults return `None`. Use Laravel's HTTP client in custom drivers to keep the same tracing and test-fake integration.

 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)
