Skip to content

Documentation

Send WordPress email through Mailtruss.

Any WordPress SMTP plugin works. So does a ten-line snippet with no plugin at all.

Before you start

You need a verified sending domain (see Domains) and an API key (under API keys in the dashboard; it is shown once). For SMTP the key is the password, and a sending-only key is enough. Keep the key in an environment variable on your server, never in code that runs in a browser or an app.

With an SMTP plugin

In the settings of any SMTP plugin (choose its "other SMTP" or "custom SMTP" option), enter these values. The API key is the password and any username works.

SMTP plugin settings
SMTP host: smtp.mailtruss.com
Port: 587
Encryption: TLS (STARTTLS)
Authentication: on
Username: mailtruss
Password: <your Mailtruss API key>
From email: hello@yourdomain.com (a verified domain)

Without a plugin

WordPress sends mail through PHPMailer, and the phpmailer_init action lets you configure it. Put this in a must-use plugin (a file in wp-content/mu-plugins) and define the key in wp-config.php, so it is not stored in the database.

wp-content/mu-plugins/mailtruss-smtp.php
<?php
// In wp-config.php: define( 'MAILTRUSS_API_KEY', 'ms_live_…' );
​
add_action( 'phpmailer_init', function ( $phpmailer ) {
$phpmailer->isSMTP();
$phpmailer->Host = 'smtp.mailtruss.com';
$phpmailer->Port = 587;
$phpmailer->SMTPAuth = true;
$phpmailer->SMTPSecure = 'tls';
$phpmailer->Username = 'mailtruss';
$phpmailer->Password = MAILTRUSS_API_KEY;
} );
​
add_filter( 'wp_mail_from', fn() => 'hello@yourdomain.com' );
add_filter( 'wp_mail_from_name', fn() => 'Acme' );

The from address

WordPress defaults to wordpress@yourdomain as the sender. The relay refuses any address on a domain you have not verified (550), so set the from address as above, on a verified domain: see [Domains](/docs/domains).

Try it without sending real mail

Most SMTP plugins have a "send test email" button. Or run this from WP-CLI. Then open the message under Emails in the Mailtruss dashboard.

Terminal
wp eval 'var_dump( wp_mail( "delivered@mailtruss.test", "Test", "Hello from WordPress" ) );'

See what happened

Open the message under Emails in the dashboard: it shows the recorded timeline, what each event proves, and a diagnosis if something went wrong. Mail sent over SMTP appears there like any other message. To be told as it happens, add a webhook.

If it fails

The relay answers with a reply code:

  • 535: the API key is wrong or revoked. Fix the password.
  • 550: refused for good (unverified domain, suppressed recipient, invalid message). Do not retry; the reply says why.
  • 552: too large, or the monthly limit is reached.
  • 451 or 452: temporary (rate limit, daily limit, or a brief problem on our side). Retry later; mail servers do this automatically.

Problems that happen after a message is accepted (bounces, complaints) are explained under delivery errors.

Other guides

Last updated

Something wrong or unclear on this page?

Report an issue