How to Fix “Mailing to Remote Domains Not Supported” Error When Sending Email from Linux Server Using mailx


2 views

The error message "Mailing to remote domains not supported" typically occurs when your Linux server's mail transfer agent (MTA) isn't properly configured to relay messages to external domains. By default, many Linux installations only allow local mail delivery.

First, let's verify your current MTA configuration:

postconf -n | grep mydestination
postconf -n | grep relayhost

For basic outgoing email functionality, you'll need to modify Postfix's main configuration file (typically /etc/postfix/main.cf):

# Set your domain
myhostname = yourdomain.com
mydomain = yourdomain.com

# Configure relay host (using Gmail as example)
relayhost = [smtp.gmail.com]:587

# Enable SASL authentication
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_use_tls = yes

Create the SASL password file:

sudo nano /etc/postfix/sasl_passwd

Add your SMTP credentials (Gmail example):

[smtp.gmail.com]:587 your.email@gmail.com:yourpassword

Then secure and compile the file:

sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd

If you don't want to configure Postfix, consider these alternatives:

Using ssmtp:

sudo apt-get install ssmtp

Configure /etc/ssmtp/ssmtp.conf:

root=your.email@gmail.com
mailhub=smtp.gmail.com:587
AuthUser=your.email@gmail.com
AuthPass=yourpassword
UseTLS=YES
UseSTARTTLS=YES

Using sendmail wrapper:

sudo apt-get install sendmail

Configure /etc/mail/sendmail.mc:

define(SMART_HOST', smtp.gmail.com')dnl
define(RELAY_MAILER_ARGS', TCP $h 587')dnl
define(ESMTP_MAILER_ARGS', TCP $h 587')dnl

After making changes, always test your configuration:

echo "Test message" | mail -s "Test Subject" recipient@example.com

# Check mail queue
mailq

# View logs in real-time
tail -f /var/log/mail.log

If emails still fail, check these common problems:

  • Firewall blocking port 587 (SMTP submission)
  • Incorrect TLS/SSL configuration
  • Gmail's "Less secure apps" setting (if using Gmail SMTP)
  • DNS resolution problems (check /etc/resolv.conf)

Never store plaintext passwords in configuration files. Consider:

  • Using app-specific passwords for services like Gmail
  • Implementing proper file permissions (600 for config files)
  • Monitoring your mail logs for suspicious activity

For serious email needs, consider:

  • Setting up SPF, DKIM, and DMARC records
  • Using dedicated email services like SendGrid or Mailgun
  • Implementing proper rate limiting
  • Setting up proper reverse DNS for your server

The error message "Mailing to remote domains not supported" typically occurs when your Linux server's mail transfer agent (MTA) isn't properly configured to relay messages outside the local system. This is a common setup issue when using basic mail utilities like mailx or sendmail.

Most Linux distributions ship with minimal mail configurations that only handle local delivery (mail between users on the same system). For external delivery (like to gmail.com), you need either:

  1. A properly configured local MTA (Postfix, Sendmail, Exim)
  2. Connection to an external SMTP relay service

For development/testing purposes, the simplest solution is to configure mailx to use an external SMTP server. Edit /etc/mail.rc:

set smtp=smtp://smtp.gmail.com:587
set smtp-use-starttls=yes
set ssl-verify=ignore
set smtp-auth=login
set smtp-auth-user=your@gmail.com
set smtp-auth-password=yourpassword

For production environments, setting up Postfix is more reliable:

sudo apt-get install postfix
# During installation select "Internet Site"
# Then configure main.cf:
sudo nano /etc/postfix/main.cf

Add these key parameters:

myhostname = yourdomain.com
relayhost = [smtp.gmail.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

For lightweight needs, ssmtp works well:

sudo apt-get install ssmtp

Configure /etc/ssmtp/ssmtp.conf:

root=your@gmail.com
mailhub=smtp.gmail.com:587
AuthUser=your@gmail.com
AuthPass=yourpassword
UseSTARTTLS=YES

After any configuration change, always test:

echo "Test message" | mail -s "Test Subject" recipient@example.com

Check logs for troubleshooting:

tail -f /var/log/mail.log

When using Gmail as relay:

  • Enable "Less secure apps" or create App Password
  • Consider rate limits (Gmail allows ~100 emails/day)
  • For production, use proper SMTP services like Amazon SES