Repository navigation
Support multiple SMTP connections with per-email selection - #32
Merged
Merged
Conversation
Providers can declare optional sending limits (per second, minute, hour, day and concurrency, for messages and recipients) with the new rate_limits key. Administrators can override the message limits for the active provider under Sending limits, and the smtp_rate_limits filter can change the result. Other plugins read it with wp_smtp_get_rate_limits(). The plugin only reports the limits, it does not queue or throttle email. Fixes #29 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A connection is a provider with its own settings, credentials, From address and sending limits. The settings saved under Tools > SMTP become the default connection, so existing sites keep working unchanged. Other connections are managed in a new Connections tab and stored in the smtp_connections option, with their secrets kept apart in the credentials storage. An email is sent through the default connection unless another one is picked, with the smtp_connection_for_email filter or the new wp_smtp_mail() function. wp_smtp_get_connections() lists the connections for other plugins without exposing credentials. The email log records the connection that sent each email, and the Test tab can test any connection. Builds on the provider rate limits of #31, since each connection has its own limits. Fixes #30 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
- Remove the Connections tab: the Settings tab now links to the default connection, the others and "Add connection", and shows the form of the selected one. Deleting a connection is a button of its form. - Generate the ID of a new connection from its name with sanitize_title(), adding a number when it is reserved or taken. The ID never changes when the connection is renamed. - Hide the sending limit fields behind a "Customize sending limits" checkbox, checked only when a limit is set. Unchecking it clears them. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
4 of 5 tasks
wp_kses_post() sorts the attributes of the link on WordPress trunk, so the current link no longer matched `class="current" aria-current="page"`. Print the link with esc_url() and esc_html() instead, which also keeps the markup stable across WordPress versions. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…-connections Conflicts resolved: - uninstall.php: keep trunk's per-site closure and remove smtp_connections inside it. - Log_Repository::insert(): keep trunk's upgrade and retry logic, add connection_id, and keep the entry without connection_id when the table still has the version 1 schema. - Test_Email::redact(): take the password fields and the values from the same connection. - Admin_Page: keep Field_Renderer and port the min and max attributes of number inputs to it. - Tests: keep both sides, plus tests for the two fixes above. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…fallback - @SInCE: the 68 tags this branch adds say 1.3.0, since 1.2.0 is already released. The changelog entry moves from the 1.2.0 section to a new 1.3.0 one. - smtp_connection_fallback action: fires when an email asks for an unknown or incomplete connection and is sent through the default one, with the ID asked for and the reason. Documented in readme.md and AGENTS.md, with tests for each case. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
davidperezgar
added a commit
to faisalahammad/smtp
that referenced
this pull request
Nov 21, 2026
Conflicts resolved: - Mailer: keep the connection hooks and settings of WordPress#32 and add use_transport() next to them. The secrets redacted from the errors of the provider are found with the fields of the connection the email goes through, not the default one (new test, which fails without it). - Provider_Registry, AGENTS.md, readme.txt: keep both the send and the rate_limits changes, and put the changelog entry in the 1.3.0 section. PHPStan, which trunk now runs, flagged this branch. Fixed: - Delivery_Tracker::remember() documents the null that Mailer passes when another plugin sends. - Transport_PHPMailer filters the redacted values with a closure, since substr() can return false on PHP 7. - Mailer uses WPINC five times, listed in the baseline like the other uses. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
faisalahammad
added a commit
to faisalahammad/smtp
that referenced
this pull request
Nov 21, 2026
Since WordPress#32, the password field is rendered by Field_Renderer for every connection, so the remove box also shows for extra connections. Check that removing it there keeps the secret of the default connection.
faisalahammad
added a commit
to faisalahammad/smtp
that referenced
this pull request
Nov 21, 2026
Since WordPress#32, the secrets of extra connections use keys like connection:sponsors:password. Secret names only accept lowercase letters, digits, hyphens and underscores, so wp_set_secret() refused them and the password of an extra connection could not be saved. - Credentials::get_secret_name() escapes the hyphen, then the colon (- to -0, : to -1), so two keys never share a name. Keys without either keep their name (smtp/password). - delete_prefixed() also deletes the secrets stored with the API, so deleting a connection removes its password there too. - Uninstall builds the names the same way.
3 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #30
What
A connection is a provider with its own settings, credentials, From address and sending limits.
default). Nothing changes for a site that never adds another one, and existing options, secrets and log rows stay valid.sanitize_title()and never changes. The sending limits are hidden behind a Customize sending limits checkbox. Writes use admin-post handlers with a nonce and amanage_optionscheck. Passwords are never printed back. Deleting a connection deletes its secrets.smtp_connection_for_emailfilter ($connection_id,$mail_data), which also routes emails sent by other plugins.wp_smtp_mail( $connection, $to, $subject, $message, $headers, $attachments ).wp_smtp_get_connections()returnsid => label, provider, configured, rate_limitswith no credentials.smtp_rate_limitsnow also receives the connection ID.connection_idcolumn in the email log (schema version 2), a Connection column in the log table once there is more than one connection, and a connection selector in the Test tab.Decisions worth a look
SMTP_HOST, ...) only configure the default connection. Otherwise they would override every connection.connection:{id}:{field}. The colon can not be part of an ID, so deletingacan never touch the secrets ofa_b.Settingsis scoped by an optional constructor argument, and the field rendering moved toAdmin\Field_Rendererso the default and the extra connections share it.Not included
wp smtpcommands still only handle the default connection.Testing
composer lintis clean.Connections_TestsandConnections_Tab_Tests, plus Mailer, Settings, Credentials, Logger, tracker, log table, Test email, Admin page and uninstall tests).wp_smtp_mail()and the Connection column of the log. Real delivery through a second connection is not tested.