Send Email to locally running SMTP server


  • Must have a smtp server running locally
  • Must have python installed


To do this we are going to be using a simple python script

So first open up a text editor

Add the following code snippet


import smtplib
from smtplib import SMTPException

sender = 'FROM_DOMAIN'
receivers = ['EMAIL_BOX']

message = """From: From Person <FROM_DOMAIN>
To: To Person <TO_DOMAIN>
Subject: SUBJECT


 smtpObj = smtplib.SMTP('localhost', PORT)
 smtpObj.sendmail(sender, receivers, message)
 print "Successfully sent email"
except SMTPException:
 print "Error: unable to send email"

replace the following variables with their correct values:

  • FROM_DOMAIN – Can be anything. Ex:
  • TO_DOMAIN -Can be anything. Ex:
  • EMAIL_BOX – The location you are sending it
  • SUBJECT – the subject of the email
  • BODY – The body of the email
  • PORT – What port your smtp server is running on

Then just make sure the file you save it in is executable

To do this from the command line it is simply

chmod +x <NAME_OF_FILE>

then execute it