The procedures below configure sendmail to work in "outbound-only" mode - that is, to relay mail from the local network onto the internet,
but NOT to receive mail from the internet. Incoming mail is handled via some other mechanism - in my case, the mail goes to my hosting provider
and then I download it with POP3.

Firstly, if you're looking to configure sendmail to accept mail FROM the internet, don't follow the instructions below, they won't work for
you. Secondly, as noted in the FreeBSD handbook, using sendmail for "outbound-only" mail is unnecessary, when ports such as ssmtp do the same
job, with a fraction of the complexity.

In an ideal world, the configuration below might be fine, but delivering your mail directly to recipients' servers - as the configuration
below does - is no longer a recommended
approach, because modern mailservers may reject mail if it does not come from a "known-good" IP address, and it's likely that the IP address
you have is NOT one of these. This is a widely-adopted anti-spam measure, and consequently using sendmail in the configuration below may
cause you to suffer delivery problems, which you may or may not find out about.

To avoid delivery problems, mail should be routed via your ISP's mailserver. It's possible to use sendmail's SMART_HOST feature for this,
but sendmail in outbound-only mode can be replaced entirely with ssmtp (ports/mail/ssmtp), which is reportedly much simpler, and no trouble to manage.

Consequently, the instructions below are deprecated, and should not be used, unless ssmtp or an equivalent is not an option for you.

configuring sendmail

Sendmail (docs: manpage - handbook) is installed and enabled by default. Use this procedure to configure it:

cd /etc/mail

cp access.sample access

vi access

comment out everything except RELAY line

change RELAY line to reflect the subnet of the local LAN (eg. 10.0.0)

In FreeBSD 8.x, the syntax of this file has changed slightly. The RELAY line now starts with "#Connect:128.32". Uncomment this line, then change it to reflect the subnet of the local LAN

save the file and quit the editor

create hostnames file: vi local-host-names

add new line: localhost

save the file and quit the editor

vi aliases

change the mailer-daemon line as follows (this is a security measure, recommended but not needed to make sendmail work):

mailer-daemon: /dev/null

save the file and quit the editor

cd /etc/mail/

make

echo sendmail_enable=\"YES\" >> /etc/rc.conf

cp freebsd.mc sendmail.mc

vi sendmail.mc

add these lines above the other FEATURE lines near the top of the file:

Where yourdomain.com is the name of the domain for which mail is being processed.

This setup permits the server to relay mail sent by any machine on the LAN, and also removes the machine's hostname from any mail originating from the machine.

verifying your sendmail configuration

The checks below ensure sendmail is correctly configured - as I need it to be on my server, which may or may not suit your own network.
In particular, this sendmail is configured in "outbound-only" mode. Use the process below if your sendmail is malfunctioning.

Note: before making ANY changes to ANY files ensure to STOP sendmail like this:

/etc/rc.d/sendmail stop

To start it when done:

/etc/rc.d/sendmail start

To check sendmail, login to the server as root, then:

cat /var/log/maillog- if the logs have been rotated, extract them to screen as follows: bzip2 -dkc /var/log/maillog.0.bz2- to show all sent items, use: cat /var/log/maillog | grep "from="- to see new log entries as they are made, use: tail -F /var/log/maillog

cat /etc/rc.conf- should contain sendmail_enable="YES"

cat /etc/mail/access- everything except the RELAY line should be commented out
- the RELAY line should contain the subnet of the local LAN, for example:

192.168 RELAY

cat /etc/mail/local-host-names- should contain one line:

localhost

cat /etc/mail/sendmail.mc- should have these lines above the other FEATURE lines near the top of the file:

WARNING: recompiling the sendmail.cf will overwrite any changes previously made to it. Ensure to create the .old file
before recompiling, and ensure to add any customisations (such as the port 587 tweak above) AFTER recompiling.
Don't forget to stop sendmail before changing anything.

Note: sendmail should be stopped before mail is deleted, then restarted afterwards (this will flush any jobs currently executing, and prevent
accidents).

sending mail from the commandline

TIP: by default, sendmail will never masquerade root's mail, which will likely prevent you from mailing from root
onto the internet (since the unmasqueraded server address cannot be resolved). There is a sendmail.cf hack (apparently) that fixes this,
but this is lame, not only will it be trashed next time sendmail.cf is recompiled, but is masquerading root's
mail a good idea? I doubt it. Instead, use sendmail's -f parameter to send mails from any user (see below).

TIP: send a mail from the command line or from a script like this:

cat messagebody.txt | mailx -s "subject" destination@mailbox.com

To use sendmail directly, defining the sender's address (you need to be root, or a trusted user, to define the sender's address):