On this page
- Why use a relay instead of sending directly?
- What do I need from the relay service?
- How do I set up Postfix as a send only relay client?
- Store the relay password safely
- How can I send a test and read the result?
- Is there a lighter option than Postfix?
- Point PHP, cron and applications at the relay
- Fix the common relay errors
- Questions
Why use a relay instead of sending directly?
A relay is the dependable path because it does not rely on outbound port 25 or on the reputation of a brand new IP address. BitcoinVPS does not promise that outgoing port 25 is open; if you want to deliver directly, open a support ticket and confirm it for your server before building on it, and request reverse DNS (PTR) in the same ticket. Submission on port 587 with authentication is the standard route for clients and applications, so the relay accepts your message, signs it, and delivers it from infrastructure that receivers already know.
Every mail page in this library, from iRedMail to a hand built Postfix server, can send its outgoing mail through the same relay settings shown here.
What do I need from the relay service?
Collect four values from your relay account: the hostname (written here as smtp.relay.example), the port (587), a username and a password or API key used as password. Most services also ask you to verify the sending domain by adding DNS records: an SPF include and one or more DKIM records. Add them now, following SPF, DKIM and DMARC records, so your messages pass alignment from the first send. Pick a From address on that verified domain, for example app@example.net.
Check that the server can reach the relay:
openssl s_client -starttls smtp -connect smtp.relay.example:587 -crlf -quiet </dev/null | head -n 5Seeing the certificate chain and a 250 reply means the network path and TLS work.
How do I set up Postfix as a send only relay client?
Postfix gives you a queue, retries and a local sendmail command that every program understands. Install it with the SASL plugins it needs for login:
sudo apt install postfix libsasl2-modules mailutils # Ubuntu, Debian (choose "Internet Site")
sudo dnf install postfix cyrus-sasl-plain s-nail # Rocky, Alma
sudo systemctl enable --now postfix
postconf mail_versionConfigure it to listen only locally, accept no mail for itself and hand everything to the relay:
sudo postconf -e "inet_interfaces = loopback-only"
sudo postconf -e "mydestination ="
sudo postconf -e "myorigin = example.net"
sudo postconf -e "relayhost = [smtp.relay.example]:587"
sudo postconf -e "smtp_sasl_auth_enable = yes"
sudo postconf -e "smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd"
sudo postconf -e "smtp_sasl_security_options = noanonymous"
sudo postconf -e "smtp_tls_security_level = encrypt"The square brackets tell Postfix to use the host as written and skip MX lookups.
Store the relay password safely
Write the credentials into a map file readable only by root, compile it and restart:
echo "[smtp.relay.example]:587 relayuser:REPLACE_WITH_SECRET" | sudo tee /etc/postfix/sasl_passwd >/dev/null
sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
sudo systemctl restart postfixThe left side must match relayhost exactly, brackets and port included. Some newer Postfix builds no longer include the hash table type; run postconf -m and, if hash is missing, use lmdb: in both the setting and the postmap command.
How can I send a test and read the result?
Send to a mailbox you own outside the server and watch the log.
echo "relay test from $(hostname)" | mail -s "relay test" -r app@example.net you@example.org
sudo tail -n 20 /var/log/mail.log # Ubuntu, Debian
sudo journalctl -u postfix -n 20 --no-pager # Rocky, Alma
mailqSuccess looks like relay=smtp.relay.example[...]:587 ... status=sent (250 ...), and mailq reports an empty queue. In the received message, the Authentication-Results header should show dkim=pass for your domain.
Is there a lighter option than Postfix?
Yes: msmtp is a tiny client with no queue and no daemon, which is ideal for a web server that sends a few messages. It ships in Ubuntu and Debian and in EPEL for Rocky and Alma.
sudo apt install msmtp msmtp-mta # Ubuntu, Debian
sudo dnf install epel-release && sudo dnf install msmtp # Rocky, Alma
msmtp --version | head -n 1Create /etc/msmtprc:
defaults
auth on
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile /var/log/msmtp.log
account relay
host smtp.relay.example
port 587
from app@example.net
user relayuser
password REPLACE_WITH_SECRET
account default : relayOn Rocky and Alma the trust file is /etc/pki/tls/certs/ca-bundle.crt. Restrict the file with sudo chmod 640 /etc/msmtprc and give its group to the user that sends, for example sudo chgrp www-data /etc/msmtprc, then create the log file with matching ownership. Test with printf "Subject: msmtp test\n\nhello\n" | msmtp you@example.org. Do not install msmtp-mta and Postfix together, as both provide sendmail.
Point PHP, cron and applications at the relay
Programs that call sendmail now go through the relay automatically: cron reports, system alerts and PHP mail(). With msmtp, set PHP explicitly in the FPM php.ini and reload the service:
sendmail_path = "/usr/bin/msmtp -t"Frameworks with their own SMTP client talk to the relay directly. Keep the secret in an environment variable (see environment variables) and use settings like these:
SMTP_HOST=smtp.relay.example
SMTP_PORT=587
SMTP_SECURE=starttls
SMTP_USER=relayuser
SMTP_PASS=REPLACE_WITH_SECRET
MAIL_FROM=app@example.netA quick Python check using only the standard library:
python3 - <<EOF
import os, smtplib
from email.message import EmailMessage
m = EmailMessage(); m["From"] = "app@example.net"; m["To"] = "you@example.org"
m["Subject"] = "python relay test"; m.set_content("it works")
with smtplib.SMTP("smtp.relay.example", 587) as s:
s.starttls(); s.login("relayuser", os.environ["SMTP_PASS"]); s.send_message(m)
EOFFix the common relay errors
- SASL authentication failed or no mechanism available: install
libsasl2-modules(Debian, Ubuntu) orcyrus-sasl-plain(Rocky, Alma), check the password, and rerunpostmap. - Connection timed out: test reachability with the
opensslcommand above; check that no outbound rule in your own firewall blocks 587. The blocked ports checks page helps narrow it down. - Sender address rejected: the From domain is not verified at the relay, or the From address differs from the one it allows.
- Mail lands in spam: confirm SPF include, DKIM and DMARC, and that the visible From domain matches the signing domain.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
| Plan | Fits because | Size | Monthly | Order from |
|---|---|---|---|---|
| A1-1 | a send only app server needs almost nothing extra | 1 vCPU, 1 GB RAM, 25 GB NVMe | $3.60/mo | $43.20 for 12 months |
Questions about Send app mail through an SMTP relay
Can this server send mail directly on port 25?
It is not promised. Ask support by ticket if you need direct delivery; the authenticated relay on 587 works either way.
Should I use port 465 instead of 587?
Both are fine if the relay offers them. Port 465 uses TLS from the first byte; 587 upgrades with STARTTLS. Pick one and set the matching TLS mode.
Do I need inbound ports for sending only?
No. A send only server opens no mail ports at all; Postfix listens on localhost and connects out to the relay.
How do I request reverse DNS?
Open a support ticket with your IP addresses and the hostname you want. With a relay, PTR matters less because the relay delivers the mail.
Can several servers share one relay account?
Yes. Use the same settings on each server, or create separate credentials per server so you can revoke one without touching the others.