A tiny and highly customizable SMTP server.
MiniSmtpServer is a small and easily customizable SMTP server. It is designed mainly to be integrated into other systems that will decide what to do with the mail that is received. By default mini-smtp-server operates as a black-hole and does not do anything with the mail being sent to it… Don't let that discourage you though, as MiniSmtpServer is designed to be extremely easy to customize which makes it fit more easily into your system!
MiniSmtpServer is based on code originally written by Peter Cooper
You may also be interested in MidiSMTPServer: github.com/4commerce-technologies-AG/midi-smtp-server/
Copyright © 2010 Aaron Gough (thingsaaronmade.com), released under the MIT license
from https://github.com/aarongough/mini-smtp-server
MiniSmtpServer is a small and easily customizable SMTP server. It is designed mainly to be integrated into other systems that will decide what to do with the mail that is received. By default mini-smtp-server operates as a black-hole and does not do anything with the mail being sent to it… Don't let that discourage you though, as MiniSmtpServer is designed to be extremely easy to customize which makes it fit more easily into your system!
To run the default server simply use: Using the server
# Create a new server instance listening at 127.0.0.1:2525
# and accepting a maximum of 4 simultaneous connections
server = MiniSmtpServer.new(2525, "127.0.0.1", 4)
# Start the server
server.start
# ...
# serving requests & doing other work here
# ...
# Shutdown the server without interrupting any connections:
server.shutdown
while(server.connections > 0)
sleep 0.01
end
server.stop
server.join
For convenience MiniSmtpServer is packaged as a RubyGem, to install it simply enter the following at your command line: Installation
gem install mini-smtp-server
MiniSmtpServer is designed to be easy to customize via subclassing. Simply subclass the `MiniSmtpServer` class and re-define the `new_message_event` event handler: Customizing the server
# This is an SMTP server that logs allThen create an instance of your new server and run it like you would normally:
# the messages it receives to STDOUT
class StdoutSmtpServer < MiniSmtpServer
def new_message_event(message_hash)
puts "# New email received:"
puts "-- From: #{message_hash[:from]}"
puts "-- To: #{message_hash[:to]}"
puts "--"
puts "-- " + message_hash[:data].gsub(/\r\n/, "\r\n-- ")
puts
end
end
server = StdoutSmtpServer.newThe possibilities are endless, and easy to implement! Want all your email stored in a database? No worries:
server.start
server.join
class DatabaseSmtpServer < MiniSmtpServerIf you have a great example of something you've done with MiniSmtpServer let me know and I will add it here!
def new_message_event(message_hash)
# Imagine we have an ActiveRecord model named 'Email'
Email.create(message_hash)
end
end
# Presto!
Author & Credits
Author | Aaron Gough |
You may also be interested in MidiSMTPServer: github.com/4commerce-technologies-AG/midi-smtp-server/
Copyright © 2010 Aaron Gough (thingsaaronmade.com), released under the MIT license
from https://github.com/aarongough/mini-smtp-server