Configure Postfix Relay

Configure Simple Relay

To configure the Linux server’s postfix software to relay mail to your SMTP server, open the postfix configuration file for editing:

vim /etc/postfix/main.cf

If your SMTP server allows relay without authentication, simply add the appropriate relayhost entry:

relayhost = exchange.customerdomain.com

Restart the postfix service to apply the settings change:

service postfix reload

Configure Relay with Authentication

Open the postfix configuration file for editing:

vim /etc/postfix/main.cf

If your SMTP server requires authentication (SMTP AUTH) and a secure connection (TLS), use the following procedure (which has been tested with Google Apps and Office365):

relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =
smtp_tls_security_level = may

Create a file where the credentials for SMTP AUTH will be stored:

vim /etc/postfix/sasl_passwd

Enter the credentials:

[smtp.gmail.com]:587 user@domain.com:password

Apply the settings:

postmap /etc/postfix/sasl_passwd
chmod 644 /etc/postfix/sasl_passwd
service postfix reload

Troubleshooting

Can’t Send Mail from Root

If your mail server requires that mail be sent from a valid address, you may have problems sending mail from the root account, which is required for backup reports and other purposes. In this case, create a mapping for the root user to a valid email address.

Add the following line to /etc/postfix/main.cf:

smtp_generic_maps = hash:/etc/postfix/generic

Add the required email address alias to /etc/postfix/generic:

root user@domain.com

Create the hash file and reload postfix:

postmap /etc/postfix/generic
service postfix reload

Vendor-Specific Notes

If you are having trouble sending outbound email with your mail server, you may refer to the hints below, or you may use a mail relay service like SendGrid.

Google

Please follow these instructions to configure postfix to relay via Google Apps or Gmail.

Microsoft Office365

Please follow these instructions to configure Office365 and postfix to work with your Eclipse server.

SendGrid

If you are having trouble with email relay using your mail server, we recommend using SendGrid.

How do I increase the maximum email size in postfix?

The postfix MTA is configured by default with resource limits that safeguard the stability of the server. One such parameter is the maximum email size, which is configured to approximately 10 MB by default. If you need to send emails larger than 10 MB:

  • Backup the /etc/postfix/main.cf configuration file
  • Edit the /etc/postfix/main.cf configuration file
  • Add a line to the bottom of the file with the desired new size. For example, if you wish to increase the size to approximately 25 MB:
message_size_limit = 25000000
  • Save the file
  • Reload sendmail
service postfix reload

For more information, please refer to the postfix documentation.

How do I troubleshoot outbound email on Linux?

Check which MTA is being used

First, determine which mail transfer agent (MTA) you are using. Currently, Eclipse Linux servers are configured using the postfix MTA. If you are running an older system, you may be using the sendmail MTA. To determine which MTA you are running, use the following command:

ls -l /etc/alternatives/mta

If the command returns a link to “/usr/sbin/sendmail.postfix”, your system is configure to use postfix. If it returns a link to “/usr/sbin/sendmail.sendmail”, your system is configured to use sendmail.

Check the SMTP relay server

Next, verify that your system is pointing to the correct SMTP relay server.

For systems using postfix, the command is:

grep ^relayhost /etc/postfix/main.cf

For systems using sendmail, the command is:

grep ^DS /etc/mail/sendmail.cf

Check the mail logs

Once you have confirmed that the MTA is relaying to the correct SMTP server, the next step is to check the email service logs. To view the last 10 log messages and monitor the file, run:

tail -f /var/log/maillog

Check the mail queue

Once you have checked the mail logs, the next step is to check the mail queue for pending and differed email messages.

mailq

Tell Postfix to process the queue now

postqueue -f

Delete all queued mail

postsuper -d ALL

Send a test message from the command line

To send a test message from the Linux command line, use the following command (replace email@domain.com with your email address):

echo test | mail email@domain.com

If you don’t receive your email, check the logs (see above) for error messages.

Send a test message from Eclipse

In a separate Eterm or Solar window, try sending an email. If you don’t receive the message, check the logs (see above). Make note of any error messages, such as “relay denied” or “cannot connect to SMTP server.” These messages are the best source for determining which element in the email service architecture is incorrect. In our experience, most issues are related to incorrectly configured SMTP relay servers, or SMTP servers that do not allow relay from the Eclipse server.