After writing a debugging / dev SMTP server as a Windows Service in Python using pywin32, I decided to figure out how to wrap the Python Windows Service into an EXE so you wouldn’t have to install Python to get it running.

I had first attempted to do this in PyInstaller but upon starting the service, Windows would report failure, but the server would still be working. I gave up on PyInstaller and found a solution in py2exe.

This was my py2exe setup.py:

from distutils.core import setup
import py2exe

setup(
    service = ["DummySMTP"],
    description = "A dummy SMTP server that logs to file.",
    modules = ["SMTPDummyServer"],
    cmdline_style='pywin32',
)

Where “DummySMTP” refers to the DummySMTP.py file in the current working directory.

To compile the EXE, run:

python setup.py py2exe

This will create two folders in the current working directory called dist and build. In the dist directory will be your EXE and other necessary files.

To install this as a service, in an administrative command prompt, run:

DummySMTP.exe -install

Please note that when the service runs, it will access that directory. So relocate the directory accordingly.

That’s it!