Posted by: jasonk2600 | November 7, 2009

Quickie HowTo – SMTP Proxy on FreeBSD

Installation

Install the Postfix SMTP server from the FreeBSD ports collection. Be sure to enable Postfix as the default mailer when prompted towards the end of the installation.

# cd /usr/ports/mail/postfix
# make install clean
# rehash

Configuration

Modify /usr/local/etc/postfix/main.cf to use the following settings. Change proxy-smtp to the hostname of your Postfix SMTP proxy system, change DMZ.yourdomain.com to the domain name that your SMTP proxy is on, change yourdomain.com to the domain of your email, and change real-mail.yourdomain.com to the fully qualified domain name of your real mail server (the final destination of the email).

myhostname = proxy-smtp.DMZ.yourdomain.com
mydomain = DMZ.yourdomain.com
mydestination = $myhostname, localhost.$mydomain, localhost
relay_domains = yourdomain.com
relayhost = [real-mail.yourdomain.com]

Enable Postfix to start at system boot and disable all Sendmail functions. Modify /etc/rc.conf to use the following settings:

sendmail_enable="NO"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"
postfix_enable=YES

Testing

Before starting Postfix for the first time, make sure that the system’s mail aliases have been updated to the Postfix format by executing the following command:

# newaliases

To begin testing the newly configured Postfix SMTP Proxy, start Postfix.

# /usr/local/etc/rc.d/postfix start

Monitor Postfix’s actions through /var/log/maillog.

# tail -f /var/log/maillog

Telnet to the Postfix SMTP server and manually send an email to a real user. Watch the output of maillog to verify that Postfix relays the message onto the real SMTP server that was specified. NOTE: Text in bold is input.

# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 proxy-smtp.DMZ.yourdomain.com ESMTP Postfix
ehlo yourdomain.com
250-proxy-smtp.DMZ.yourdomain.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from: realuser1@yourdomain.com
250 2.1.0 Ok
rcpt to: realuser2@yourdomain.com
250 2.1.5 Ok
data
354 End data with .
This is a test message!
.
250 2.0.0 Ok: queued as 5D31B11432
quit
221 2.0.0 Bye
Connection closed by foreign host.

Maillog should show something similar to the following. NOTE: You can see that Postfix queued the message to be relayed onto real-mail.yourdomain.com.

Nov  6 16:50:06 horus postfix/postfix-script[30772]: starting the Postfix mail system
Nov  6 16:50:06 proxy-smtp postfix/master[30773]: daemon started -- version 2.6.5, configuration /usr/local/etc/postfix
Nov  6 17:00:32 proxy-smtp postfix/smtpd[30808]: connect from localhost[127.0.0.1]
Nov  6 17:00:51 proxy-smtp postfix/smtpd[30808]: 5D31B11432: client=localhost[127.0.0.1]
Nov  6 17:00:57 proxy-smtp postfix/cleanup[30811]: 5D31B11432: message-id=<20091107010051.5D31B11432@proxy-smtp.DMZ.yourdomain.com>
Nov  6 17:00:57 proxy-smtp postfix/qmgr[30775]: 5D31B11432: from=, size=371, nrcpt=1 (queue active)
Nov  6 17:00:57 proxy-smtp postfix/smtp[30812]: 5D31B11432: to=, relay=[real-mail.yourdomain.com]:25, delay=14, delays=13/0.01/0.07/0.43, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as A837417097)
Nov  6 17:00:57 proxy-smtp postfix/qmgr[30775]: 5D31B11432: removed
Nov  6 17:00:58 proxy-smtp postfix/smtpd[30808]: disconnect from localhost[127.0.0.1]

 [EoF]
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: