Using Python built-in SMTP server for development and troubleshooting

Using Python built-in SMTP server for development and troubleshooting

Python has a built-in SMTP module, which can act as an email SMTP server and can be started on your workstation for development or troubleshooting purposes. It doesn't actually send the email to the target destination - emails are discarded and printed to the stdout.

Photo by Davide Baraldi


The only requirement is the correct installation of Python.

Start SMTP server

Open command prompt (for Windows: Win+R -> cmd; for Linux: open terminal) and run the next command:

python -m smtpd -c DebuggingServer -n

This will start the SMTP server and binds TCP port 1025 to the loopback interface of your host. You can replace with any of the IP addresses for this host (like for example, or with the host DNS name (, or with to listen on all interfaces. After the command is executed, there will be no output in the CLI. The server now waits for the new connections.

Sending test email

Now to test our SMTP server we will send a test email message using telnet. You can read more about how to use telnet to send emails here:

Sending emails with Telnet
Little note on how to verify SMTP server reachability and how to send emails with Telnet app with and without authentication.

Open another command prompt and type the next commands:

telnet 1025

You will see the output of the telnet command trying to connect to the specified host and port and the server welcome message:

Connected to
Escape character is '^]'.
220 Python SMTP proxy version 0.3

Now we need to identify ourselves, type:


The server will reply with its capabilities:

250 HELP

Set email sender and recipients with the mail from: and rcpt to commands:

mail from:
250 OK
rcpt to:
250 OK

Email addresses in this case do not really matter, they can be non-existent.

Enter the message body by sending first the data command:

354 End data with <CR><LF>.<CR><LF>

followed by the actual Subject of the email and its contents:

Subject: Test email

Hello! This is the test
Hope you will see it.

- User

Finally, enter one blank line and finish the body input with the single .:

250 OK

Now you can enter the quit command to end the session.

In the first command prompt window, where we started the SMTP server, you will see the message:

---------- MESSAGE FOLLOWS ----------
b'Subject: Test email'
b'Hello! This is the test'
b'Hope you will see it.'
b'- User'
------------ END MESSAGE ------------

It means that you did everything right.

Share Tweet Send
You've successfully subscribed to Prox blog
Great! Next, complete checkout for full access to Prox blog
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.