Skip to content
This repository has been archived by the owner on May 30, 2021. It is now read-only.

Commit

Permalink
Updated Readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongough committed Nov 5, 2010
1 parent 86945c6 commit f4e90df
Showing 1 changed file with 70 additions and 1 deletion.
71 changes: 70 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
@@ -1,9 +1,78 @@
= mini-smtp-server

mini-smtp-server 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 stores any mail it receives in an SQLite database, which makes it easy to use this database an interface for other software to retrieve the emails.
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 the system is designed to be extremely easy to customize which makes it fit more easily into your system!

=== Installation

MiniSmtpServer is packaged as a RubyGem, so installing it is as easy as:

gem install mini-smtp-server

=== Using the server

To run the default server simply use:

# Create a new server instance listening at 127.0.0.1:2525
# and accepting a maximum of 4 simultaneous connections
server = MiniSmtpServer.new(port_number = 2525, host = "127.0.0.1", max_connections = 4)

# Start the server
server.start

# ...
# serving requests
# ...

# Shutdown the server without interrupting any connections:
server.shutdown
while(server.connections > 0)
sleep 0.01
end
server.stop
server.join

=== Customizing the 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:

# This is an SMTP server that logs all
# 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

Then create an instance of your new server and run it like you would normally:

server = StdoutSmtpServer.new
server.start
server.join

The possibilities are endless, and easy to implement! Want all your email stored in a database? No worries:

class DatabaseSmtpServer < MiniSmtpServer
def new_message_event(message_hash)
# Imagine we have an ActiveRecord model named 'Email'
Email.create(message_hash)
end
end

# Presto!

If you have a great example of something you've done with MiniSmtpServer let me know and I will add it here!

=== Author & Credits

Author:: {Aaron Gough}[mailto:aaron@aarongough.com]

MiniSmtpServer was inspired by code written by {Peter Cooper}[http://peterc.org/]

Copyright (c) 2010 {Aaron Gough}[http://thingsaaronmade.com/] ({thingsaaronmade.com}[http://thingsaaronmade.com/]), released under the MIT license

0 comments on commit f4e90df

Please sign in to comment.