Setup opensmtpd on FreeBSD to send only from localhost with Gmail

killall and disable sendmail before run it

# pkg install opensmtpd
# touch /etc/mail/secrets
# chmod 640 /etc/mail/secrets
# chown root:_smtpd /etc/mail/secrets
# echo 'gmail yourgmail:yourpassword' > /etc/mail/secrets
# ee /usr/local/etc/mail/smtpd.conf

paste this

table secrets file:/etc/mail/secrets
listen on localhost
action "relay" relay host smtp+tls://gmail@smtp.gmail.com:587 auth <secrets>
match from local for any action "relay"

check the opensmtpd config

# smtpd -n

enable opensmtpd in service

# sysrc smtpd_enable=YES

start opensmtpd service

# service smtpd start

test

# echo "Does it work?" | mail -s "Mail test from OpenBSD" your@email.com