Skip to content

Commit

Permalink
Sending speed: docs and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
macuk committed Apr 13, 2012
1 parent 9e24226 commit 8457256
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
12 changes: 10 additions & 2 deletions README.md
@@ -1,6 +1,6 @@
# Mailing

Tool for sending fast mailings
Tool for sending fast mailings in one SMTP connection.

## Installation

Expand All @@ -16,6 +16,11 @@ Or install it yourself as:

$ gem install mailing

## Sending speed

Default sending speed is low and set to ~ 120 mails per minute.
You can change that value by setting the delay parameter in sender.

## Step by step usage

require 'mailing'
Expand All @@ -32,6 +37,7 @@ Or install it yourself as:
# create sender with channel, envelope_from and logger
logger = Logger.new('/tmp/mailing.log')
sender = Mailing::Sender.new(channel, 'sender@domain.com', logger)
sender.delay = 0.1 # ~ 600 mails per minute

# create mailing with from, subject, body, recipients
mailing = Mailing::Mailing.new('from@domain.com', 'Subject', 'Body')
Expand All @@ -52,7 +58,9 @@ Or install it yourself as:
:port => 25,
:domain => 'localhost.localdomain'
}
mailing.send_by_smtp(config, 'sender@domain.com')
# send with config and envelope_from set to sender@domain.com
# without logging and with 0.2 delay (~ 300 mails per minute)
mailing.send_by_smtp(config, 'sender@domain.com', nil, 0.2)

## Rails usage

Expand Down
1 change: 1 addition & 0 deletions lib/mailing.rb
@@ -1,4 +1,5 @@
require 'mailing/version'
require 'mailing/delay'
require 'mailing/mailing'
require 'mailing/sender'
require 'mailing/smtp_channel'
3 changes: 3 additions & 0 deletions lib/mailing/delay.rb
@@ -0,0 +1,3 @@
module Mailing
DELAY = 0.5
end
4 changes: 2 additions & 2 deletions lib/mailing/mailing.rb
Expand Up @@ -13,9 +13,9 @@ def send(sender)
sender.send(self)
end

def send_by_smtp(config, envelope_from, logger=nil)
def send_by_smtp(config, envelope_from, logger=nil, delay=DELAY)
channel = SmtpChannel.new(config)
sender = Sender.new(channel, envelope_from, logger)
sender = Sender.new(channel, envelope_from, logger, delay)
send(sender)
end

Expand Down
4 changes: 3 additions & 1 deletion lib/mailing/sender.rb
@@ -1,8 +1,10 @@
require 'mailing/delay'

module Mailing
class Sender
attr_accessor :channel, :envelope_from, :logger, :delay

def initialize(channel, envelope_from, logger=nil, delay=0.5)
def initialize(channel, envelope_from, logger=nil, delay=DELAY)
@channel = channel
@envelope_from = envelope_from
@logger = logger
Expand Down
2 changes: 1 addition & 1 deletion mailing.gemspec
Expand Up @@ -4,7 +4,7 @@ require File.expand_path('../lib/mailing/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ["Piotr Macuk"]
gem.email = ["piotr@macuk.pl"]
gem.description = %q{Tool for sending fast mailings}
gem.description = %q{Tool for sending fast mailings in one SMTP connection}
gem.summary = %q{Fast mailings}
gem.homepage = "https://github.com/macuk/mailing"

Expand Down

0 comments on commit 8457256

Please sign in to comment.