How to Install a Simple,
Independent SMPTD Server
on Your macOS Computer

Click or Tap Icons to Share! Thank you!
Authored By  :
Bill Kochman

Published On :
October 14, 2023

Last Updated :
October 14, 2023


NOTE: Being as this tutorial employs a lot of unix command strings, which will appear broken up on a cell phone, this tutorial is best viewed on a desktop or a laptop computer.

Introduction


This tutorial is the collective work of Sabahattin Gucukoglu and Bill Kochman. It is the result of installing OpenSMTPD on a Retina 5K, 27-inch, 2017 iMac running macOS Ventura 13.6, for the purposes of sending email notifications from my old school messageboard. Your mileage may vary if OpenSMTPD is installed on a different Apple computer under a different version of macOS.

NOTE: Please note that this installation is designed for personal use on a small scale, and is not meant for high volume mail traffic.

The SMTP server we are going to install is totally independent of the sendmail and postfix binaries which are installed on your macOS machine by default at /usr/sbin. You do NOT need to touch either sendmail or postfix, or their configuration files in any way. Pretend that they are not even there.

Requirements


1. This tutorial requires that you know how to use the macOS Terminal app -- located in /Applications/Utilities -- and how to install different programs, binaries and supporting files. Don't let this frighten you. Even if you are a novice with using the Terminal, if you carefully follow these instructions without any deviation, you should hopefully meet with success.

2. Aside from having a macOS computer, you must have Admin privileges on the machine where you are installing OpenSMTPD.

3. In order to install certain system packages and their dependencies, you must have MacPorts installed. One reason why MacPorts is preferred over Homebrew, is because MacPorts installations are totally separate from macOS, and thus do not interfere with the performance of your native macOS system. Also, some packages may not be available from the Homebrew repository. The easiest method for installing MacPorts is to download the package installer for your particular version of macOS from the following URL:

https://www.macports.org/install.php

NOTE: If you wish to browse the manual for MacPorts -- although it is not necessary for this installation -- you can type the following in the Terminal, and then hit your "return" key, AFTER installing MacPorts:

man port


4. In order for this setup to work, you will need to get a free "app password" from Google. This will of course require that you have a Gmail account. You will also need to have 2-Step Verification enabled with your Gmail account. For instructions regarding how to acquire an app password, please go to the following URL:

https://support.google.com/accounts/answer/185833?hl=en

NOTE: To make things go as smoothly and efficiently as possible, I suggest that you open a dedicated Gmail account which will be specifically used with your SMTPD installation. Likewise, I encourage you to open this new Gmail account, and set up your app password, on the same machine where you will be installing SMTPD.

Once you have installed MacPorts on your machine -- if it isn't already installed -- and have acquired your app password from Google, you are ready to begin the installation of OpenSMTPD on your machine.

OpenSMTPD Installation


After launching the Terminal app, use MacPorts to install OpenSMTPD and the required certificate authorities with the following command. Hit your "return" key after typing in the command. You will be prompted to enter your Admin password:

sudo port install opensmtpd curl-ca-bundle

You can do the same thing with two separate commands like the following, although it is not necessary to do it this way:

sudo port install opensmtpd

sudo port install curl-ca-bundle

In both cases, you will be required to hit your "return" key after typing in the command, and then to enter your Admin password.

NOTE: If you want to learn more about the SMTPD configuration file, at this point, you can type the following in the Terminal, followed by hitting your "return" key:

man smtpd.conf

The above installation will place a copy of the "sendmail" binary -- totally independent of the "sendmail" binary installed by default by Apple -- in the following directory:

/opt/local/sbin/

OpenSMTPD Configuration


Now it is time to configure the SMTPD server. The SMTPD configuration I am about to share with you will allow your system to accept local submissions via CLI -- Command Line Interface (meaning via the Terminal) -- and via the socket interface. Regardless of the destination email address that you input, it will relay your message to Gmail with your credentials. This will be explained more clearly in a moment.

The configuration parameters are entered into the "smtpd.conf" file, which you will find at the following path. This path starts at the top level of your hard drive:

/opt/local/etc/opensmtpd/smtpd.conf

Once you have located the "smtpd.conf" file, you need to open it with a text editor -- NOT a word processor app -- such as Apple's TextEdit, BBEdit, or any other text editor of your choice. If you have already gotten this far, then it is assumed that you have Admin privileges on your machine. The simplest thing to do would be to drop the "smtpd.conf" file on top of the icon of your chosen text editor, either in the Finder, or even in the Dock.

Once you have opened the "smtpd.conf" file, you need to first delete its ENTIRE contents so that it is completely BLANK. Then, you need to copy and paste the following text into the "smtpd.conf" file; but not just yet. There is something else we need to do first:

# TBD: No local delivery, credentials in config for clarity. But works on
# trusted machine for simple CLI submission
action to-gmail relay \
    host smtps://credentials@smtp.gmail.com:465 \
    auth { "credentials" = "my-special-gmail@gmail.com:my-special-app-pwd" }
match from local for any action to-gmail

NOTE: While we are using a Gmail address and a Google app password in our example, you are free to use any provider of your choosing, if you have the required experience to set up an email account, and to acquire the necessary app password from that provider. However, that is beyond the scope of this current tutorial.

NOTE: To avoid potential typing mistakes, I strongly encourage you to copy and paste all of the above text, rather than typing it in manually.

Now please pay attention, because it is very important. Where you see "my-special-gmail@gmail.com" in that text, you need to REPLACE it with the Gmail account address that you created earlier in this same tutorial. Likewise, where you see "my-special-app-pwd" in the text, you need to REPLACE it with the 16-character app password you acquired earlier in this tutorial.

NOTE: When you type in the 16-character app password, do NOT include the spaces, as you see it on Google's website.

The above is the ONLY text which should be in the "smtpd.conf" file. After you are certain that you have made the proper substitutions in the file -- make sure that you don't accidentally delete the colon between your special Gmail address and your app password -- you can save the file using command-s. Upon saving it, you will be required to enter your Admin password again.

To verify that your "smtpd.conf" file is properly configured, type the following at the Terminal prompt. If everything is fine, you should get an "OK" response:

sudo smtpd -n

Being as you made some changes to the "smtpd.conf" file, you need to reload the opensmtpd binary by typing the following command in the Terminal:

sudo port reload opensmtpd

If everything has gone according to plan, the sendmail binary which is located at the following path is now your new mail submission binary:

/opt/local/sbin/sendmail

Verify Your Credentials With Google


Before proceeding to run an actual test of your new SMTPD server, you may wish to verify that your credentials are okay with Google. This is not an absolutely necessary step, but it could be helpful in some situations.

To do this, you need to type the following command in the Terminal AFTER making two edits to it. Please note that this all goes on ONE line, and that there is a space between -s and 'smtps:

smtp -v -v -n -s 'smtps://yourspecialgmail@gmail.com:abcdabcdabcdabcd@smtp.gmail.com:465'

Again, please pay close attention. Where the command says "yourspecialgmail@gmail.com", you need to once again REPLACE it with the Gmail address that you created earlier in this tutorial. Likewise, you need to REPLACE "abcdabcdabcdabcd" with your actual Google app password which you acquired earlier in this tutorial, making sure to remove the blank spaces in it. Finally, again, make certain that you do not accidentally delete the colon that is located between your email address and your app password.

Once you type the above command string with your proper Gmail address and proper Google app password included in it, followed by hitting your "return" key, the Terminal will spit back a pile of information. Amidst all of that information, you will see a string which includes the following:

<<< 235 2.7.0 Accepted

If so, congratulations! You are now ready to conduct your first actual test of your new SMTPD server setup.

OpenSMTPD Testing


To test your new SMTPD server -- meaning the new "sendmail" installation -- type the following at the Terminal prompt, and then hit your "return" key:

/opt/local/sbin/sendmail -t

On the next blank lines which follow, type each of the lines below, followed by hitting your "return" key once, AFTER making the proper edits accordingly.

NOTE: The easiest thing to do would probably be to copy the text below into a plain text file, make the required edits, and then copy and paste each line into the Terminal one line at a time, hitting the "return" key after each line:

From: Me <my-special-gmail@gmail.com>
To: my-actual-real-gmail@gmail.com
Subject: My SMTPD Server Test

IMPORTANT: The "my-special-gmail@gmail.com" string should be REPLACED with the SAME new Gmail address that you created earlier in this tutorial. The "my-actual-real-gmail@gmail.com" can be REPLACED with any email account address where you personally receive email. How else will you be able to determine whether or not your new SMTPD server setup is working properly. :)

To be clear, after you type "/opt/local/sbin/sendmail -t" as discussed earlier, your Terminal window should look something like the following:

$ /opt/local/sbin/sendmail -t
From: Me <my-special-gmail@gmail.com>
To: my-actual-real-gmail@gmail.com
Subject: My SMTPD Server Test

After typing "My SMTPD Server Test" as shown above, enter a blank line by pressing your "return" key twice. Then type the following text, followed by hitting your "return" key once:

This is a test of my new SMTPD server setup. I sure hope it works properly.

On the new line right below the above text string, next type the following:

control-d

This command informs the Terminal app that it should register an EOF -- or End of File -- on your input. In other words, it tells the Terminal that you want to exit and be returned to the Terminal prompt.

Test the Results


Now comes the exciting moment: Finding out if your email was properly delivered to the email address that you specified. Simply log into your Gmail account for that email address and have a look in your inbox. If you don't see it there, you may also want to check your Sent, Spam and Bin -- or Trash -- folders.

Hopefully, this moment will put a big smile on your face, as it did for me, after meticulously working on this project for two days with my online friend, Sabahattin Gucukoglu.

If for some reason you should not find the email you sent from your SMTPD server, run the following command in the Terminal app in order to determine if there is still any mail in your mail queue. You will be prompted to enter your Admin password:

sudo mailq

If you see no results upon entered that command, it means that there are no email messages queued up, and that there may possibly be something wrong.

If that turns out to be the case, I invite you to join us on the "TidBITS" forum at the URL below. Someone there will be glad to try to help you to work through your issues with your SMTPD setup:

https://talk.tidbits.com/c/tidbits-talk/6

On the other hand, if you did in fact receive the sent email, congratulations! You can now use the following path in whatever app or script you need to in order to send and receive email:

/opt/local/sbin/sendmail

In my particular case, I used the above string in my message forum script's mail settings, so that it knows where to find the proper "Sendmail" binary. Let me emphasize again that this is a DIFFERENT "Sendmail" binary from what is installed by macOS. This is an independent "Sendmail" binary which was installed by MacPorts in our earlier steps, for the purpose of using your new SMTPD server.

On a last note, let me also mention that in addition to pointing my messageboard to the right "Sendmail" binary, I also had to input the SAME email address that is found in the SMTPD configuration file. That is the email address that I use to send out email FROM my server.

I hope the above information has been helpful to you in resolving some of your own SMTP/sendmail issues.

Visit counter For Websites


Click or Tap Icons to Share! Thank you!

BBB Tools And Services


Please avail yourself of other areas of the Bill's Bible Basics website. There are many treasures for you to discover.