Send Email from a VPS When Port 25 Is Blocked: SMTP Relay on Port 587

IM Host Editorial4 min read
SMTP relay configuration on port 587 from a VPS

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

PortPurposeEncryptionUse from a VPS app?
25Server-to-server delivery between mail serversOptional STARTTLSAvoid; often restricted
587Submission: authenticated clients and apps sending through a mail serverSTARTTLSYes, the recommended choice
465Submission with implicit TLS from the first byteTLSWorks 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]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt
inet_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_passwd
sudo postmap /etc/postfix/sasl_passwd
sudo 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=smtp
MAIL_HOST=smtp.yourprovider.com
MAIL_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 with echo "test" | mail -s "test" [email protected] after Postfix is set up.
  • Read the log: sudo tail -f /var/log/mail.log or journalctl -u postfix.

Common errors

ErrorMeaningFix
Connection timed out on port 25Outbound 25 is restrictedSwitch to 587 with authentication
535 Authentication failedWrong username or password, or app password requiredCheck credentials; some providers need an app-specific password
Must issue a STARTTLS command firstTLS not enabledEnable STARTTLS (Postfix: smtp_tls_security_level = encrypt)
Sender address rejectedFrom address not allowed for this accountSend from the authenticated address or an allowed alias
Mail arrives in spamMissing SPF, DKIM or DMARC alignmentAdd 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.

IM Host EditorialNovember 25, 2026All articles