# WordPress plugin

The Voozin plugin sends every email WordPress and your plugins send (password resets, WooCommerce orders, form notifications) through the Voozin API instead of the server's PHP mail. It also receives email: messages to an address such as `support@yoursite.com` appear in an inbox inside wp-admin, grouped into conversations, and you can reply from there.

- Works with WordPress 6.2+ and PHP 7.4+.
- No SMTP plugin needed; mail goes over HTTPS, so it works on hosts that block SMTP ports.
- Free and open source (GPLv2 or later).

## Install

- From WordPress: **Plugins → Add New**, search for **Voozin**, then **Install** and **Activate**.
- Or download [voozin-wordpress.zip](https://voozin.com/downloads/voozin-wordpress.zip) and upload it under **Plugins → Add New → Upload Plugin**.

## Connect your account

1. In Voozin, [verify your domain](https://voozin.com/docs/domains) and create an API key under **Developers → API keys** with the scopes `emails:send` and `domains:read`. For the inbox, also add `webhooks` and `inbound`.
2. In WordPress, open **Voozin → Settings** and paste the key. To keep it out of the database, add it to `wp-config.php` instead:

   ```php
   define( 'VOOZIN_API_KEY', 'ic_live_...' );
   ```

3. Choose the **From** address: pick one of your verified domains from the list and enter the address and name, for example `WordPress <no-reply@yoursite.com>`.
4. Click **Send test email**.

From now on, every call to `wp_mail()` goes through Voozin. Plugins that set their own From address on a verified domain keep it; other From addresses are replaced with yours, so mail is never sent from a domain that would fail SPF and DKIM.

## Settings

| Setting | What it does |
| --- | --- |
| From address and name | The default sender for WordPress mail |
| Force From address | Always use your From address, even when a plugin sets another one |
| Fallback to PHP mail | If the Voozin API cannot be reached or rejects an email, send it with WordPress's default mailer instead of failing. The log shows the Voozin error. |
| Track opens and clicks | Overrides your domain's tracking defaults for WordPress mail |
| Keep log for | How long the email log is kept (default 30 days) |

## Email log

**Voozin → Email log** lists every email WordPress sent: time, recipient, subject, and status. When the inbox is connected, the status updates from delivery webhooks (delivered, bounced, complained), so you can see why a customer never got their password reset.

## Inbox: receive and reply

1. Open **Voozin → Inbox** and click **Connect**. The plugin creates a webhook endpoint in Voozin pointing to `https://yoursite.com/wp-json/voozin/v1/webhook` and stores its signing secret.
2. Under **Receiving addresses**, enter the address to receive and choose the domain, for example `support`, a prefix such as `reply+*`, or `*` for every address without a mailbox. Click **Add address** to create the inbound route.
3. Repeat for more addresses. **Disconnect this site** deletes the webhook and routes in Voozin.

Your domain's `MX` record must point to Voozin (the domain page in Voozin shows it).

Received messages appear under **Voozin → Inbox**, grouped into conversations by their `In-Reply-To` and `References` headers. Open one to read it, download attachments, and reply. Replies are sent from the address the message was sent to and thread in the sender's mail app.

Your WordPress site must be reachable from the internet over HTTPS to receive webhooks.

## For developers

When a message arrives, the plugin fires an action with the stored post id and the full [inbound.received](https://voozin.com/docs/inbound) data:

```php
add_action( 'voozin_inbound_received', function ( int $post_id, array $message ) {
    if ( 0 === strpos( $message['subject'] ?? '', '[Order' ) ) {
        // create a WooCommerce order note, a ticket, a lead…
    }
}, 10, 2 );
```

Other hooks:

- `voozin_event_received` (`$event`): every verified webhook event, including `email.*` events.
- `voozin_email_payload` (filter, `$payload`, `$atts`): change the API request before it is sent, for example to add `tags`.

Messages are stored as a private post type (`voozin_message`) and are not visible on the front end. Uninstalling the plugin deletes its settings, log and stored messages, and removes the webhook and routes it created in Voozin.

## Troubleshooting

- **Test email fails with 403**: the key is missing the `emails:send` scope, or it is restricted to another domain.
- **Test email fails with 402**: the organization's plan doesn't include transactional email, or the trial has reached its included amount.
- **The inbox stays empty**: check the domain's `MX` record and the delivery log of the webhook in Voozin (**Developers → Webhooks**). Security plugins and firewalls must allow `POST` requests to `/wp-json/voozin/v1/webhook`.
