=== Mail Doctor ===
Contributors: Sarfraj Yusuf
Tags: woocommerce, email, smtp, deliverability, logging
Requires at least: 6.0
Tested up to: 6.9
Requires PHP: 8.1
Stable tag: 1.0.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Deliver WooCommerce emails with confidence using authenticated SMTP transports, visual diagnostics, and automated retries.

== Description ==

Mail Doctor replaces WordPress' default `wp_mail` stack with authenticated SMTP or provider APIs plus the operational tooling fast-moving stores need. It is written for merchants, agencies, and reliability teams that want hard proof their receipts, fulfillment notices, and alerts land every time.

= Feature Highlights =

* **Deliverability with guardrails** – Route WooCommerce or all site email through your preferred SMTP/API provider, lock the From identity, and fail over gracefully when third-party endpoints go dark.
* **One-click diagnostics** – Send live tests with TLS/auth badges, latency metrics, DNS posture (SPF/DKIM/DMARC), and actionable warnings the moment something drifts.
* **Reliable retries & queue control** – Automatic exponential backoff, manual retry orchestration, Action Scheduler integration, and a “run queue now” control for urgent flushes.
* **Deep visibility** – Searchable logs with `.eml` downloads, header/body inspection, filterable status views, and CSV exports for audits.
* **Email template workflow** – Version history, diff previews, modal device switcher, and send-test flows for the WooCommerce template editor.
* **Automation surface** – REST API endpoints and WP-CLI commands mirror UI actions so you can script smoke tests, tail logs, or trigger retries in CI/CD pipelines.
* **Privacy-first options** – Hash or redact recipients, tune retention windows, and honour GDPR requests through the bundled exporters/erasers.
* **Operational alerts** – Instant Slack/email failure alerts plus weekly digests summarising throughput, latency, retries, and queue health.

== External Services ==

This plugin acts as a connector between your WordPress site and third-party email providers. When you configure an external service (SMTP or API), this plugin transmits email data to that provider for delivery.

**Data Sent:**
*   Sender and Recipient names and email addresses.
*   Email subject, body content (HTML/Text), and headers.
*   Timestamps and potentially the originating IP address.

**When Payload is Sent:**
*   Immediately whenever an email is triggered by WordPress, WooCommerce, or another plugin, *if* that specific provider is currently set as your active transport.

**Purpose:**
*   To reliably deliver transactional emails to user inboxes using the provider's infrastructure.

**Supported Services & Legal Links:**

*   **Google / Gmail**
    *   [Terms of Service](https://policies.google.com/terms)
    *   [Privacy Policy](https://policies.google.com/privacy)
    *   **Endpoints**: `accounts.google.com`, `oauth2.googleapis.com`

*   **Microsoft / Outlook / Office 365**
    *   [Terms of Use](https://www.microsoft.com/en-us/legal/terms-of-use)
    *   [Privacy Statement](https://privacy.microsoft.com/en-us/privacystatement)
    *   **Endpoints**: `login.microsoftonline.com`, `outlook.office365.com`

*   **Twilio SendGrid**
    *   Links: [terms of service](https://www.twilio.com/en-us/legal/tos), [privacy policy](https://www.twilio.com/en-us/legal/privacy)
    *   **Endpoints**: `api.sendgrid.com`

*   **Mailgun**
    *   Links: [terms of service](https://www.mailgun.com/legal/terms/), [privacy policy](https://www.mailgun.com/legal/privacy-policy/)
    *   **Endpoints**: `api.mailgun.net`, `api.eu.mailgun.net` (and other region equivalents)
    *   **Domain validation**: When you click "Verify Domain" in the plugin settings, the plugin queries `https://api.mailgun.net/v3/domains/{your-domain}` (or the EU equivalent) to check DNS records (SPF, DKIM, MX). Data sent: your Mailgun API key and the domain name. No email content is transmitted during this check.

*   **Amazon SES**
    *   Links: [terms of service](https://aws.amazon.com/service-terms/), [privacy policy](https://aws.amazon.com/privacy/)
    *   **Endpoints**: `email.us-east-1.amazonaws.com`, `email-smtp.us-east-1.amazonaws.com` (and other `*.amazonaws.com` region equivalents)

*   **Postmark**
    *   Links: [terms of service](https://postmarkapp.com/terms), [privacy policy](https://postmarkapp.com/privacy)
    *   **Endpoints**: `api.postmarkapp.com`

*   **SparkPost**
    *   Links: [terms of service](https://www.sparkpost.com/policies/tou/), [privacy policy](https://www.sparkpost.com/policies/privacy/)
    *   **Endpoints**: `api.sparkpost.com`

*   **Brevo (formerly Sendinblue)**
    *   Links: [terms of service](https://www.brevo.com/legal/termsofuse/), [privacy policy](https://www.brevo.com/legal/privacypolicy/)
    *   **Endpoints**: `smtp-relay.brevo.com` (SMTP relay); configurable SMTP host per your provider settings.
    *   This plugin transmits the same email data (sender, recipients, subject, body) to Brevo's SMTP relay servers when Brevo is configured as the active transport.

**OAuth Authentication Endpoints:**

When you connect Google or Microsoft accounts using OAuth2, this plugin communicates with the following authentication endpoints to obtain and refresh access tokens:

*   **Google OAuth2**
    *   Authorization: `https://accounts.google.com/o/oauth2/v2/auth`
    *   Token exchange: `https://oauth2.googleapis.com/token`
    *   Data sent: Client ID, authorization code, and redirect URI
    *   [Google API Terms of Service](https://developers.google.com/terms)
    *   [Google Privacy Policy](https://policies.google.com/privacy)

*   **Microsoft OAuth2 (Outlook/Office 365)**
    *   Authorization: `https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize`
    *   Token exchange: `https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token`
    *   Data sent: Client ID, client secret, authorization code, and redirect URI
    *   [Microsoft API Terms of Use](https://docs.microsoft.com/en-us/legal/microsoft-apis/terms-of-use)
    *   [Microsoft Privacy Statement](https://privacy.microsoft.com/en-us/privacystatement)

= Quick Start =

1. Review the documentation link in the Documentation section for the full tour and terminology.
2. Configure SMTP/API credentials on **WooCommerce → Mail Doctor → Settings**.
3. Send a test email from the **Status** tab and verify DNS/auth posture.
4. Visit **Logs** to confirm entries are stored and retries are scheduled as expected.
5. Enable alerts and weekly digests so the team knows when to act.

= Documentation =

Documentation: https://wpdoctorpro.com/docs/mail-doctor/welcome-to-mail-doctor – guides, setup, troubleshooting, and support.

= Privacy controls =

Mail Doctor ships with built-in privacy tooling under **Settings → Logging & Privacy**:

* **Mask recipient emails:** Hashes addresses before storing them in logs.
* **Redact headers and bodies:** Keeps metadata only so sensitive content is not persisted.
* **Retention windows:** Separate sliders for sent, failed, and payload data; shorten for stricter compliance.
* **GDPR exporter/eraser:** WordPress privacy tools are wired to export or anonymise recipient rows on request.
* **Role-based access:** Admin UI and AJAX endpoints are gated by `manage_woocommerce`/`manage_options`.

= Troubleshooting =

* Red notices on the Status tab usually indicate DNS or authentication drift—re-run the onboarding checks and confirm credentials with your provider.
* If the queue stalls, visit **Settings → Retry & Queue** and use **Run queue now**; check your cron runner or Action Scheduler if jobs remain pending.
* Use the `.eml` download from each log entry when escalating to your SMTP provider—they can analyse the exact payload and SMTP transcript.
* For privacy incidents, toggle Privacy Mode and shorten retention while you investigate; the GDPR exporter/eraser handles customer requests.

== Support & Packaging ==

* Requirements: WordPress 6.0+, WooCommerce (latest), PHP 8.1–8.3 with cURL/JSON; OpenSSL recommended for encrypted secret storage.
* Included in download: `mail-doctor/` plugin folder, `Documentation/` offline HTML docs, `readme.txt`, `changelog.txt`, and `LICENSE`.
* Support/Contact: See the Documentation section for guides and support links. When requesting help, include your WP/Woo versions, provider, and a recent log ID from **Mail Doctor → Logs**.

== Installation ==

1. Upload the `mail-doctor` folder to `/wp-content/plugins/` or install via the WordPress admin.
2. Activate the plugin.
3. Navigate to **WooCommerce → Mail Doctor → Settings** and enter your SMTP credentials.
4. Use the **Status** tab to send a test message and review diagnostics.

Detailed installation and provider recipes are available in the Documentation section.

== Frequently Asked Questions ==

= Does this plugin send all emails over SMTP? =

By default, only WooCommerce emails are routed through SMTP. You can toggle the scope to **All wp_mail calls** on the settings tab.

= Which SMTP providers are supported? =

Any provider offering SMTP access (SendGrid, Mailgun, SES, Postmark, Gmail with App Passwords, etc.). Use the appropriate host, port, encryption, username, and password supplied by your provider.

= Will Mail Doctor work without WooCommerce? =

Most features (SMTP override, logging, retries) work without WooCommerce. Woo-specific tools (previews, email toggles) require WooCommerce to be active.

= Where are logs stored? =

Email activity is stored in the custom database table `{prefix}maildoctor_log`. Logs are automatically pruned based on the retention period set in the plugin settings (default 30 days).

= How do retries work? =

Failed emails are marked with a retry schedule using exponential backoff. A cron worker (`maildoctor_retry_cron`) runs every five minutes to process due entries. You can also trigger a manual retry from the Logs tab.

= How can I get help? =

See the Documentation section for configuration guides and playbooks. If you are on a support contract, provide log IDs and the output of `wp maildoctor status` when you reach out so the team can assist quickly.

== Screenshots ==

1. Admin Dashboard: Status dashboard with diagnostics and DNS checks.
2. SMTP Settings: SMTP settings with multiple provider.
3. Mail Log: Email log viewer with filtering and retry controls.
4. Mail Dcotor Guide: Guide to use Mail Doctor & Support.

== Changelog ==

= 1.0.1 =
* Fixed an issue where the plugin was not properly deleted on uninstall.

= 1.0.0 =
* Launch release with authenticated SMTP/API transports plus provider presets for Mailgun, SendGrid, SES, Postmark, SparkPost, and generic HTTP relays.
* Added test email workflows (WP admin, REST API, and WP-CLI) with TLS/auth diagnostics, DNS posture, and latency metrics.
* Introduced searchable email logging with `.eml` exports, CSV downloads, manual retry, quarantine, and queue draining controls.
* Delivered privacy tooling (hashing, redaction, retention policies), capability checks, and GDPR exporter/eraser integrations.
* Included Mail Doctor docs hub with onboarding guide, provider recipes, and troubleshooting playbooks for hand-offs.
