Mail Forwarding With Sendmail on FreeBSD

This is a guideline on how to enable sendmail as a mail forwarding service with Freebsd on a Digitalocean droplet or any other VPS.

Sendmail Configurations

/etc/mail/access

Under this directory we need to copy or create access that “defines which hosts or IP addresses have access to the local mail server and what kind of access they have”.

% sudo cp access.sample access
% sudo vi access

We need to add the domain and kind of access it will have

# $FreeBSD: releng/11.0/etc/mail/access.sample 176353 2008-02-17 05:22:08Z gshapiro $
#
# Mail relay access control list. Default is to reject mail unless the
# destination is local, or listed in /etc/mail/local-host-names
#
topup.ph RELAY
/etc/mail/virtusertable

We also need to copy or create the list of virtual users

% sudo cp virtusertable.sample virtusertable

then add the emails that you want to relay to, in my case I created a catch all email. This means that whatever email address is sent to topup.ph will be forwarded to my personal email account.

# $FreeBSD: releng/11.0/etc/mail/virtusertable.sample 68266 2000-11-02 23:32:31Z dirk $
#
# Map one or all usernames at a source hostname to a specific (or the same)
# username at another target hostname. Remember to add the source hostname
# to /etc/mail/local-host-names so that sendmail will accept mail for the
# source hostname.
#
@topup.ph myemail@gmail.com
/etc/mail/local-host-names

As stated in our /etc/mail/access config, “Mail relay access control list. Default is to reject mail unless the destination is local, or listed in /etc/mail/local-host-names” so we need to create the file and add our domain name.

% sudo vi local-host-names

then add the your domain

topup.ph

We need to recompile our configuration and restart the sendmail daemon

% make
% sudo service sendmail restart

Sendmail Service

After configuring sendmail, we need to make sure that we enable sendmail every time our server restart.

/etc/rc.conf

Add the following configuration

sendmail_enable="YES"
sendmail_submit_enable="YES"
sendmail_submit_flags="-L sm-mta -bd -q30m
-ODaemonPortOptions=Addr=topup.ph"

Firewall

Of course, we also need to allow incoming and outgoing connections to our smtp service,

% sudo vi /etc/ipfw.rules

then add

$cmd 00230 allow tcp from any to any 25 out via $pif setup keep-state

we need to restart our ipfw rule sets,

% sh /etc/ipfw.rules

We also need to check if the port is open,

% sockstat -4 -l

You should see something like

USER COMMAND  PID   FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
root sendmail 21199 3  tcp4  *:25          *:*

Resources:

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