1

I'm sorry if this might sound confusing at first.

My brother asked me to make a web server for him because he wanted to self host his own website and not use a hosting service anymore. The problem with this is the ISP. Besides the dynamic IP scheme, they block outgoing TCP connections on port 25, and instead they offer their external server which requires no authentication.

For the web server setup I have chosen FreeBSD, as I prefer jails to virtual machines or running the services directly on the host machine. It makes backing up and security management a lot easier (at least for me).

For the moment I have disabled sendmail completely, but I wish to enable it again, so users can make use of the recover password function when necessary. My question is, how can I configure sendmail to use an external SMTP without user or password authentication?

Thank you in advance for your help!

  • Google how to configure a smart host in sendmail. However, this doesn’t sound like a plan that is going to work, because I think it is unlikely the ISP is providing an email server that’s going to just allow you to randomly relay messages through it. So, I think you are misunderstanding what they are offering. With that said, why wouldn’t you just upgrade to a business class service with a static IP? Hopefully this website isn’t too important, as nobody would do what you are doing if it was. – Appleoddity Feb 1 at 7:31
  • It actually does allow any address to send any email, as long as it doesn't contain an attachment. I've tested it even using random nonesense addresses. It does defeat the purpose in case of spam, but they say it's for preventing smtp enabled viruses to spread. I've found instructions for setting up sendmail to use authentication, but since I've never used it before, I don't presume the instructions are the same for non authenticated SMTP. As for the importance, it's the website promoting his electrician company's services. He used to have a static address. I don't know why he doesn't now. – Comrade Zed Feb 1 at 11:07
  • 1
    You define a SMART_HOST (see /etc/mail/freebsd.mc) and rebuild the sendmail.cf file. I don't have a step by step guide, but the makefile in /etc/mail/ may be able to do it. – Richard Smith Feb 1 at 14:41
1

Both of the comments to your post are on the right track. Here is a more fully fledged response.

(TL;DR at bottom)

As root, start by making a safety copy of your /etc/mail directory:

# cd /etc
# cp -Rp mail mail.safety

For the purposes of this example, I'm going to assume that you have no customizations to your email configuration, and in fact, we'll start by "zeroing-out" your existing sendmail files to ensure that we start with a clean slate. If you do have customizations, not to worry, we started off by making a backup of those files. You can re-apply your customizations later.

First move into the mail directory and remove your existing *.cf files:

# cd mail
# rm *.cf

It is common on FreeBSD systems to have a $(hostname).mc file and a $(hostname).submit.mc file, in addition to the stock freebsd.mc and freebsd.submit.mc files that are distributed with the OS. Here is the output of ls on a system with the simple hostname test:

# ls *.mc
freebsd.mc         freebsd.submit.mc     test.mc         test.submit.mc

You will probably see similar files, but referencing your own machine's hostname. The reason behind this is that the freebsd*.mc files represent the basic starting point for sendmail configuration. The $(hostname)*.mc files are (potentially) customized files that are specific to your system. While an OS upgrade may well overwrite the freebsd*.mc files, it will not touch your host-specific files, so your carefully customized configs will not be overwritten by an OS upgrade. Your part of that bargain is that you should confine your changes to the $(hostname)*.mc files and leave the freebsd*.mc reference files untouched.

Throughout the remainder of this tutorial, I will use the string test to represent places where you should see your machine's hostname as part of a filename.

So with that background, let's continue.

Remove your $(hostname)*.mc files so that the Makefile will clone your configuration from the known-good freebsd*.mc files.

# rm -v $(hostname)*.mc
test.mc
test.submit.mc

Now that we've removed your old config files, let's run make to create new ones based on the freebsd.mc and freebsd.submit.mc files provided by the OS:

# make
cp -f freebsd.mc test.mc
/usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/   /usr/share/sendmail/cf/m4/cf.m4 test.mc > test.cf
cp -f freebsd.submit.mc test.submit.mc
/usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/   /usr/share/sendmail/cf/m4/cf.m4 test.submit.mc > test.submit.cf

That actually does a little more than we need, but that's alright. The important thing is that the Makefile copied freebsd.mc to $(hostname).mc and freebsd.submit.mc to $(hostname).submit.mc.

Now, let's inspect the $(hostname).mc file. At or near line 89 (of the file I'm looking at for FreeBSD 12) is the SMART_HOST directive that the previous authors have mentioned:

# grep SMART_HOST $(hostname).mc
dnl define(`SMART_HOST', `your.isp.mail.server')

The 'dnl' at the beginning of the line means the line is commented out. DNL can be thought to stand for "Discard (or ignore) until NewLine."

Edit your .mc file:

# vi $(hostname).mc

and change that line to read:

define(`SMART_HOST', `smtp.example.com')

where smtp.example.com is the DNS name of the server your ISP told you to use. Be sure to remove the "dnl" also. Save the file and exit.

Now run make to re-generate your $(hostname)*.cf files:

# make
/usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/   /usr/share/sendmail/cf/m4/cf.m4 test.mc > test.cf
/usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/   /usr/share/sendmail/cf/m4/cf.m4 test.submit.mc > test.submit.cf

Run make install to copy your $(hostname)*.cf files to the standard names that sendmail expects (sendmail.cf and submit.cf):

# make install
install -m 444 test.cf /etc/mail/sendmail.cf
install -m 444 test.submit.cf /etc/mail/submit.cf

Restart sendmail:

# make restart

Finally, inspect /var/log/maillog to ensure there are no errors.


TL;DR

# cd /etc
# cp -Rp mail mail.safety
# cd mail
# rm *.cf
# rm -v $(hostname)*.mc
# make
# vi $(hostname).mc

Change the SMART_HOST line to read:

define(`SMART_HOST', `smtp.example.com')

and continue:

# make
# make install
# make restart

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.