Testing an SMTP credential before going live: a test e-mail from the command line

E-mail·· 63 views· 3 min read

This article is for people with access to a command line (a VPS, the cPanel terminal when the account has SSH, or your own computer). The short answer: before you put the credential into the program, send a test e-mail with it from the same machine the program will run on. If the test works, the credential, the port and the network are fine, and any error that shows up later is in the program settings.

With swaks

swaks is a small tool made for testing SMTP; install it from your distribution package manager. The first line asks for the password without showing it and without leaving it in the history:

read -s SMTP_PASSWORD
swaks --server SMTP_HOST --port 587 --tls \
--auth-user SMTP_USER --auth-password "$SMTP_PASSWORD" \
--from no-reply@yourcompany.com --to you@example.com

For port 465, replace --port 587 --tls with --port 465 --tlsc. swaks shows the whole conversation with the server, line by line.

With Python, nothing to install

python3 - <<'END'
import getpass, smtplib
s = smtplib.SMTP("SMTP_HOST", 587); s.starttls()
s.login("SMTP_USER", getpass.getpass("Password: "))
s.sendmail("no-reply@yourcompany.com", ["you@example.com"], "Subject: Test\r\n\r\nSMTP Relay test")
s.quit()
END

Reading the answer

What you see Means What to do
A reply starting with 250 at the end The relay accepted the e-mail. Check it in the Email Center log and in your mailbox.
Authentication error (code 535) Wrong username or password, or a revoked credential. Check what you copied, or create a new credential.
Sender refused The sender domain is not verified. Use an address on the verified domain.
It hangs with no answer The port is blocked on this machine network. Try 465. See which ports are open.
Never type the password straight into the command. It stays in the shell history and, on a shared server, can show up in the process list. Both examples above ask for it without showing it.
To see the SMTP conversation command by command, by hand, there is the openssl s_client test.

Test failing and you cannot see why? Open a ticket with what the command showed, without the password.

Open a support ticket

SEE ALSO

SMTP Relay not sending: connection, TLS, login, sender and recipient problems, one by one

Testing IMAP, POP3 and SMTP by hand with openssl s_client: a guide for technical users

Which ports are open, and why your integration hangs without an error

Sending through SMTP Relay from Node.js and Python: Nodemailer and smtplib, with STARTTLS

The program says sent, the customer got nothing: finding SMTP e-mails in the Email Center log

RECOMMENDED PRODUCT

Professional e-mail on your domain

Mailboxes in your company name, no adverts, with spam filtering. from $6.60/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.