Your app on a VPS needs to send password resets, order confirmations or alerts, but emails never arrive, or the connection to port 25 times out. Many hosting and cloud providers restrict outbound port 25 on new or entry-level servers, because it is the port spammers abuse. The reliable fix is not to fight the block: send through an authenticated SMTP relay on the submission port 587. This guide explains the ports, then shows how to configure Postfix, WordPress, Laravel and Node.js to relay mail properly.
SMTP ports in one table
| Port | Purpose | Encryption | Use from a VPS app? |
|---|---|---|---|
| 25 | Server-to-server delivery between mail servers | Optional STARTTLS | Avoid; often restricted |
| 587 | Submission: authenticated clients and apps sending through a mail server | STARTTLS | Yes, the recommended choice |
| 465 | Submission with implicit TLS from the first byte | TLS | Works with many providers, but may be restricted on some plans |
On IM HOST, outbound ports 25 and 465 are restricted for new accounts on some entry-level plans as an anti-spam measure. Use 587 with authentication, and contact support if you are unsure what is open on your plan.
Why relaying beats running your own mail server
- Deliverability: a new VPS IP has no sending reputation, and many receivers treat it with suspicion. A relay sends from IPs with established reputation.
- Less to maintain: no spam filtering, queues, blacklists or reverse DNS to manage for outgoing mail.
- Authentication built in: SPF and DKIM are set up once for the relay, so your messages pass checks. See SPF, DKIM and DMARC for business email.
The relay can be your business email provider's SMTP server (fine for low volume, such as contact forms and alerts) or a transactional email service (better for high volume, such as order emails and newsletters). Check your provider's sending limits.
Option 1: Postfix as a relay (system mail and cron alerts)
Install Postfix and choose "Satellite system" or "Internet with smarthost" during setup, then edit /etc/postfix/main.cf:
relayhost = [smtp.yourprovider.com]:587smtp_sasl_auth_enable = yessmtp_sasl_password_maps = hash:/etc/postfix/sasl_passwdsmtp_sasl_security_options = noanonymoussmtp_tls_security_level = encryptinet_interfaces = loopback-only
Create /etc/postfix/sasl_passwd with one line:
[smtp.yourprovider.com]:587 [email protected]:YOUR_PASSWORD
Then protect and load it, and restart:
sudo chmod 600 /etc/postfix/sasl_passwdsudo postmap /etc/postfix/sasl_passwdsudo systemctl restart postfix
inet_interfaces = loopback-only makes sure your server does not accept mail from the internet, so it cannot become an open relay. On Ubuntu and Debian, install libsasl2-modules if authentication fails.
Option 2: Configure the app directly
WordPress
WordPress sends with PHP's mail function by default, which often fails on a VPS without a local mail server. Install an SMTP plugin and enter host, port 587, encryption TLS, username and password. Send the plugin's test email to confirm.
Laravel
In .env:
MAIL_MAILER=smtpMAIL_HOST=smtp.yourprovider.comMAIL_PORT=587[email protected]MAIL_PASSWORD=your_password[email protected]
Clear the config cache with php artisan config:clear after changes. Depending on your Laravel version, an encryption or scheme setting may also apply; use TLS/STARTTLS for 587.
Node.js (Nodemailer)
Create a transport with host, port: 587, secure: false (STARTTLS is negotiated after connecting) and auth with your username and password. Use secure: true only with port 465.
Test the connection
- Check the port is reachable:
nc -vz smtp.yourprovider.com 587 - Check STARTTLS:
openssl s_client -starttls smtp -connect smtp.yourprovider.com:587 - Send a test from the command line with a tool such as
swaks, or withecho "test" | mail -s "test" [email protected]after Postfix is set up. - Read the log:
sudo tail -f /var/log/mail.logorjournalctl -u postfix.
Common errors
| Error | Meaning | Fix |
|---|---|---|
| Connection timed out on port 25 | Outbound 25 is restricted | Switch to 587 with authentication |
| 535 Authentication failed | Wrong username or password, or app password required | Check credentials; some providers need an app-specific password |
| Must issue a STARTTLS command first | TLS not enabled | Enable STARTTLS (Postfix: smtp_tls_security_level = encrypt) |
| Sender address rejected | From address not allowed for this account | Send from the authenticated address or an allowed alias |
| Mail arrives in spam | Missing SPF, DKIM or DMARC alignment | Add the relay to SPF and enable DKIM for your domain |
Security tips
- Use a dedicated mailbox or SMTP credential for each app, not your personal mailbox password.
- Keep credentials in environment files with restricted permissions, never in public repositories.
- Rate-limit contact forms and add CAPTCHA or honeypot fields to stop abuse.
Need a reliable sender for your app? IM HOST business email hosting gives you mailboxes on your domain with SMTP on port 587, and runs alongside your Linux VPS. For help with your setup, contact support.



