This is a guideline on how to enable sendmail as a mail forwarding service with Freebsd on a Digitalocean droplet or any other VPS.
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
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 email@example.com
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
We need to recompile our configuration and restart the sendmail daemon
% make % sudo service sendmail restart
After configuring sendmail, we need to make sure that we enable sendmail every time our server restart.
Add the following configuration
sendmail_enable="YES" sendmail_submit_enable="YES" sendmail_submit_flags="-L sm-mta -bd -q30m -ODaemonPortOptions=Addr=topup.ph"
Of course, we also need to allow incoming and outgoing connections to our smtp service,
% sudo vi /etc/ipfw.rules
$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 *:*