Okay let’s set up your freebsd 8 system to use gmail as its MTA. This guide will assist you in setting up your server to send email via gmail with a secure logon. We’re replacing sendmail with ssmpt because ssmpt is so much easier to configure and sendmail is overkill when you just need to send system mail and such. We’ll use gmail to relay the emails to the destination for us. So the flow will be a system job like cron will generate an email – your freeBSD server will send login to your gmail (securely) and use gmail to send the email. Gmail will limit you to 5,000 emails per day.
You’ll need a freeBSD server – ssmtp installed – a gmail account – about 5 minutes spare time
ssmtp will replace sendmail – all systems commands that use sendmail with automatically now use ssmtp – the sendmail command will still work just ssmpt will be used
Disable Sendmail completely by setting the following in your /etc/rc.conf file:
make install replace clean
Configure SSMTP – located here –> cd /usr/local/etc/ssmtp/ssmpt.conf
enable ssmpt at boot
echo ‘ssmtp_enable=“YES”’ >> /etc/rc.conf
FreeBSD says you need a wrapper but the doc is old or just incorrect – when you issue the make install replace clean that updates /etc/mail/mailer.conf with the correct info
Chad Perrin at Techrepublic laid down a useful explanation of the ssmtp.conf file options. I’ve included them below.
* email@example.com: This identifies what user account receives all mail for userid under 1000 on the local system. That basically means system accounts, such as the root user account. In other words, if your computer is trying to send your root account an e-mail message, it will send it to whatever e-mail address you specify her. This should normally be your primary e-mail account — probably the account for which you’re configuring sSMTP to send e-mails.
* AuthUser=username: The username indicated here should be the username used to log into the remote SMTP server. In many cases, this is the part of the e-mail address that comes before the @ sign in your e-mail address. In some cases, it may be the entire e-mail address, possibly with the @ replaced by a plus sign. Using the firstname.lastname@example.org example above, this means it the username entry might be user+example.com, depending on the SMTP server configuration.
* AuthPass=password: When authenticating, this is the password used with the username above. Because my e-mail password is stored in the file, I make sure the ssmtp.conf file permissions are set to 640 using the chmod command. This ensures that the ssmtp and system administrator accounts can access the file as needed (both to make sure the ssmtp process works properly and that I can edit the file as root when needed), but no unprivileged accounts have access to the contents of the file. For this to work, you will also need to ensure that you create an ssmtp user (with a command like pw useradd ssmtp -g nogroup -h – -s /sbin/nologin -d /nonexistent -c “sSMTP pseudo-user”) and set ownership of ssmtp.conf to that user (with a command like chown ssmtp ssmtp.conf).
* mailhub=mail.example.com: Set the mailhub option to the fully qualified hostname for the SMTP server you will be using, so that sSMTP knows where to send outgoing e-mails. This option may actually take the form mailhub=mail.example.com:465, which sets the port number to use when contacting the SMTP server to 465. This allows unencrypted connections to use 25 (the default port number for SMTP traffic), and 465 is the standard alternate port number for TLS- and SSL-protected SMTP connections.
* rewriteDomain=example.com: This tells sSMTP that your mail headers need to be edited to say that the domain name you use for your e-mail address will be listed as the source of your e-mail address. Failing to rewrite the source domain name in this manner may cause problems at the receiving end when your e-mail address arrives at its intended destination.
* hostname=hostname.domain: The hostname indicated here is the hostname of the computer you are using to compose and send e-mails. The .domain part may or may not be present. On Unix and Linux systems, you can find the hostname for your computer by entering the command hostname at the shell prompt.
* FromLineOverride=YES: The From: header in an e-mail handled by sSMTP can be overwritten at this point. Setting this to YES just uses the From: value provided by the program that sent the e-mail to sSMTP to be forwarded to the SMTP server in the first place. In my case, since I use mutt as my mail user agent, this means that setting FromLineOverride=YES will cause sSMTP to use whatever From: header line mutt provides.
* UseTLS=YES: At last, we’ve struck gold. This is the configuration line that tells sSMTP to encrypt its connection to the SMTP server, protecting your authentication username and password as well as the rest of the session.
Ben Francom says
Nice writeup. This came in handy this morning, and worked flawlessly. I’m using it for my FreeBSD router logs.
kids math games says
pass it on