GoAdmio

checksmtp

Check that the server's SMTP service accepts a login on port 587 by sending a test email, try to repair it automatically, and alert the administrator when it keeps failing

On this page: Overview · Quick start · Syntax · Options · Output · Examples · Troubleshooting · Details · See also


Overview

/go/checksmtp makes sure that people can send email through your server. It:

The command does not check the SSL certificate. To check the certificates for SMTP and IMAP, use checkmail and checkimap.

[!WARNING] Each test sends a real email to a fixed address, gbp.uae@gmail.com, written in the script, from the mailbox of one of your users. A single run can send up to three. See Known issues.


Quick start

/go/checksmtp

Syntax

/go/checksmtp

The command takes no options or arguments. Run it as root. It needs curl and dig.


Options

None. Any arguments you pass are ignored.


Output

The command prints nothing when the first test succeeds. Other results:

Message Meaning
Invalid Hostname (<hostname>), A hostname should consist of a name and a domain name. All valid hostnames should have 2 dots in them. The server host name has fewer than 2 dots. The administrator is alerted and the command stops.
Please Point <hostname> to A Record: <server-ip> The host name does not resolve to this server's public IP. The administrator is alerted and the command stops.
SMTP failed. Our system is trying to fix it automatically. The first test failed. The mail configuration was rebuilt, and the test is run again.
SMTP error was automatically corrected. The second test succeeded.
CHECKSMTP: SMTP Server <hostname> is not working. All three tests failed. The administrator is alerted.

Each run also adds a line to /var/log/go/checksmtp.log.

The command ends with status 1 even when the test succeeds. Do not use its exit status to detect errors.

When nothing is tested

The command stops without any message, and without sending a test, in these cases:

Case Why
An outgoing SMTP relay is configured There is at least one entry in the SMTP relay list (/var/lib/sqlite/smtp.db), so the command assumes the relay is used.
The public IP of the server cannot be found The IP lookup returned nothing.
No mailbox has sent mail today There is no account to test with. In this case the command only rebuilds the mail maps with vmail.

Examples

# Run the check
/go/checksmtp
# Test the login on port 587 yourself
curl -v --url smtp://127.0.0.1:587 --user 'user@example.com:password' --mail-from user@example.com --mail-rcpt you@example.net -T /dev/null
# Check that the host name points to this server
dig $(cat /etc/hostname) +short

Troubleshooting

Symptom Likely cause Fix
Invalid Hostname The server host name is not a full name such as server.example.com. Change it with hostname.
Please Point ... to A Record The A record is missing or points to another IP. Point the A record to the IP shown. If the record is proxied by Cloudflare, set it to DNS only. See proxy.
Nothing is printed, and you expect a test A relay is configured, or no mailbox has sent mail today. See When nothing is tested.
CHECKSMTP: SMTP Server ... is not working. Postfix, Dovecot, or the SSL certificate is broken, or port 587 is blocked. Check the firewall with checkfirewall, the certificates with mailssl, and see troubleshoot.
Test emails arrive at an address you do not know The recipient is written in the script. See Known issues.
No alert arrives The administrator's email or WhatsApp settings are missing. Check them with config and email.

Details

What it does, in order

  1. Logs the run to /var/log/go/checksmtp.log.
  2. Reads the server host name from /etc/hostname. If it has fewer than 2 dots, prints the message, alerts the administrator, and stops.
  3. Gets the server's public IPv4 address. If that fails, stops.
  4. Looks up the host name's A record with dig and compares the last answer with the server IP. If they differ, prints the message, alerts the administrator, and stops.
  5. If the SMTP relay list is not empty, stops.
  6. Chooses the mailbox that has sent the most mail today and reads its password from the mail database. If there is none, goes to the last step.
  7. Test 1. Logs in to port 587 of the server's public IP and sends a test email. If the reply contains 250, 252, or 235, stops.
  8. If test 1 failed, runs the internal postconf helper and vmail to rebuild the Postfix configuration and mail maps, and prints SMTP failed....
  9. Test 2. Same test. If it succeeds, prints SMTP error was automatically corrected. and stops. If not, runs installmail to configure Postfix and Dovecot again.
  10. Test 3. Same test. If it succeeds, stops. If not, prints CHECKSMTP: ... is not working. and alerts the administrator by email and WhatsApp.
  11. Rebuilds the mail maps with vmail.

Known issues


See also

Command Description
checkimap Check the IMAP port and SSL certificate
checkmail Check if your server provider supports mail port 25 (SMTP)
mailssl Install SSL certificates for SMTP and IMAP
installmail Install and configure webmail services (Postfix and Dovecot)
vmail Rebuild the Postfix/Dovecot vmail maps
smtp Manage the SMTP port: block, unblock, and change it
troubleshoot Troubleshoot email problems in GoAdmio