smailer 0.6.3 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +12 -4
- data/generators/smailer/templates/migration.rb.erb +10 -13
- data/lib/generators/smailer/templates/migration.rb.erb +10 -13
- data/lib/smailer/models.rb +1 -0
- data/lib/smailer/models/mail_campaign.rb +6 -0
- data/lib/smailer/models/mail_campaign_attachment.rb +19 -0
- data/lib/smailer/tasks/send.rb +9 -0
- data/lib/smailer/version.rb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c72c27e350a0cd53f23e5b4e961f4addceea0fff
|
4
|
+
data.tar.gz: 6c4fe79f61f4e3ec824d1b6f33d6b9177a9e7ba0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78a7371b1ec129605f13b0998ad7dc8a41ee462ab077213becdbd88d6bf43e03eda6dd5fdf6ca571e8891a7fc1c5685c0b6393f781b41ef859aee875784dd286
|
7
|
+
data.tar.gz: 9a9fcd6397f2735e5fd8eb8c5fdb5a7056831c994c69b9b52ec2d06f8162c0a2fe55b777a9c923ba921e98e6e2fb3b5770c6c606e24239f24655f53dba18e137
|
data/README.md
CHANGED
@@ -54,7 +54,7 @@ Here is an example how you could proceed with creating and issuing a newsletter:
|
|
54
54
|
|
55
55
|
# locate the mailing list we'll be sending to
|
56
56
|
list = Smailer::Models::MailingList.first
|
57
|
-
|
57
|
+
|
58
58
|
# create a corresponding mail campaign
|
59
59
|
campaign_params = {
|
60
60
|
:from => 'noreply@example.org',
|
@@ -66,7 +66,10 @@ Here is an example how you could proceed with creating and issuing a newsletter:
|
|
66
66
|
campaign = Smailer::Models::MailCampaign.new campaign_params
|
67
67
|
campaign.add_unsubscribe_method :all
|
68
68
|
campaign.save!
|
69
|
-
|
69
|
+
|
70
|
+
# Add attachments
|
71
|
+
campaign.add_attachment 'attachment.pdf', 'url_or_file_path_to_attachment'
|
72
|
+
|
70
73
|
# enqueue mails to be sent out
|
71
74
|
subscribers = %w[
|
72
75
|
subscriber@domain.com
|
@@ -77,10 +80,15 @@ Here is an example how you could proceed with creating and issuing a newsletter:
|
|
77
80
|
campaign.queued_mails.create! :to => subscriber
|
78
81
|
end
|
79
82
|
|
83
|
+
### Attachments
|
84
|
+
|
85
|
+
You can have zero or more attachments to any mail campaign. As demonstrated in the example above, you add them to the campain using the `MailCampaign#add_attachment(file_name, url_or_path)` method.
|
86
|
+
|
87
|
+
Any attached files will be referenced at the moment of sending and must be reachable and readable by the send task. Currently, `open-uri` is used to fetch the content of the path or URI. The maximum length of the path/URI field is 2048 symbols.
|
80
88
|
|
81
89
|
### Managing unsubscriptions
|
82
90
|
|
83
|
-
Among the few unsubscription methods supported, probably the most widely used one is unsubscription via a unsubscribe link in the email.
|
91
|
+
Among the few unsubscription methods supported, probably the most widely used one is unsubscription via a unsubscribe link in the email.
|
84
92
|
|
85
93
|
In order to help you with implementing it, Smailer provides you with some interpolations you can use in the email's body:
|
86
94
|
|
@@ -145,7 +153,7 @@ Suppose you manage your site's newsletter subscriptions via a `Subscription` mod
|
|
145
153
|
:subscribed_checker => subscribed_checker,
|
146
154
|
}) do |unsubscribe_details|
|
147
155
|
subscription = Subscription.confirmed.subscribed.where(:email => unsubscribe_details[:recipient]).first
|
148
|
-
|
156
|
+
|
149
157
|
if subscription
|
150
158
|
subscription.subscribed = false
|
151
159
|
subscription.unsubscribe_reason = 'Automatic, due to bounces'
|
@@ -37,6 +37,15 @@ class CreateSmailerTables < ActiveRecord::Migration
|
|
37
37
|
add_index "queued_mails", ["locked", "retries", "id"], :name => "index_queued_mails_on_locked_retries_and_id"
|
38
38
|
add_index "queued_mails", ["locked", "locked_at"], :name => "index_queued_mails_on_locked_and_locked_at"
|
39
39
|
|
40
|
+
create_table "mail_campaign_attachments", :force => true do |t|
|
41
|
+
t.integer "mail_campaign_id", :null => false
|
42
|
+
t.string "filename", :null => false
|
43
|
+
t.string "path", :limit => 2048
|
44
|
+
t.datetime "created_at"
|
45
|
+
t.datetime "updated_at"
|
46
|
+
end
|
47
|
+
add_index "mail_campaign_attachments", "mail_campaign_id"
|
48
|
+
|
40
49
|
create_table "finished_mails", :force => true do |t|
|
41
50
|
t.integer "mail_campaign_id"
|
42
51
|
t.string "from"
|
@@ -79,23 +88,11 @@ class CreateSmailerTables < ActiveRecord::Migration
|
|
79
88
|
|
80
89
|
def self.down
|
81
90
|
drop_table :smailer_properties
|
82
|
-
|
83
|
-
remove_index :mail_keys, :name => "index_mail_keys_on_email"
|
84
|
-
remove_index :mail_keys, :name => "index_mail_keys_on_email"
|
85
91
|
drop_table :mail_keys
|
86
|
-
|
87
|
-
remove_index :finished_mails, :name => "index_finished_mails_on_key"
|
88
|
-
remove_index :finished_mails, :name => "index_finished_mails_on_mail_campain_id_and_status"
|
89
|
-
remove_index :finished_mails, :name => "index_finished_mails_on_to_and_mail_campaign_id"
|
90
92
|
drop_table :finished_mails
|
91
|
-
|
92
|
-
remove_index :queued_mails, :name => "index_queued_mails_on_mail_campain_id_and_to"
|
93
|
-
remove_index :queued_mails, :name => "index_queued_mails_on_retries"
|
94
93
|
drop_table :queued_mails
|
95
|
-
|
96
|
-
remove_index :mail_campaigns, :name => "index_mail_campaigns_on_mailing_list_id"
|
94
|
+
drop_table :mail_campaign_attachments
|
97
95
|
drop_table :mail_campaigns
|
98
|
-
|
99
96
|
drop_table :mailing_lists
|
100
97
|
end
|
101
98
|
end
|
@@ -37,6 +37,15 @@ class CreateSmailerTables < ActiveRecord::Migration
|
|
37
37
|
add_index "queued_mails", ["locked", "retries", "id"], :name => "index_queued_mails_on_locked_retries_and_id"
|
38
38
|
add_index "queued_mails", ["locked", "locked_at"], :name => "index_queued_mails_on_locked_and_locked_at"
|
39
39
|
|
40
|
+
create_table "mail_campaign_attachments", :force => true do |t|
|
41
|
+
t.integer "mail_campaign_id", :null => false
|
42
|
+
t.string "filename", :null => false
|
43
|
+
t.string "path", :limit => 2048
|
44
|
+
t.datetime "created_at"
|
45
|
+
t.datetime "updated_at"
|
46
|
+
end
|
47
|
+
add_index "mail_campaign_attachments", "mail_campaign_id"
|
48
|
+
|
40
49
|
create_table "finished_mails", :force => true do |t|
|
41
50
|
t.integer "mail_campaign_id"
|
42
51
|
t.string "from"
|
@@ -79,23 +88,11 @@ class CreateSmailerTables < ActiveRecord::Migration
|
|
79
88
|
|
80
89
|
def self.down
|
81
90
|
drop_table :smailer_properties
|
82
|
-
|
83
|
-
remove_index :mail_keys, :name => "index_mail_keys_on_email"
|
84
|
-
remove_index :mail_keys, :name => "index_mail_keys_on_email"
|
85
91
|
drop_table :mail_keys
|
86
|
-
|
87
|
-
remove_index :finished_mails, :name => "index_finished_mails_on_key"
|
88
|
-
remove_index :finished_mails, :name => "index_finished_mails_on_mail_campain_id_and_status"
|
89
|
-
remove_index :finished_mails, :name => "index_finished_mails_on_to_and_mail_campaign_id"
|
90
92
|
drop_table :finished_mails
|
91
|
-
|
92
|
-
remove_index :queued_mails, :name => "index_queued_mails_on_mail_campain_id_and_to"
|
93
|
-
remove_index :queued_mails, :name => "index_queued_mails_on_retries"
|
94
93
|
drop_table :queued_mails
|
95
|
-
|
96
|
-
remove_index :mail_campaigns, :name => "index_mail_campaigns_on_mailing_list_id"
|
94
|
+
drop_table :mail_campaign_attachments
|
97
95
|
drop_table :mail_campaigns
|
98
|
-
|
99
96
|
drop_table :mailing_lists
|
100
97
|
end
|
101
98
|
end
|
data/lib/smailer/models.rb
CHANGED
@@ -2,6 +2,7 @@ module Smailer
|
|
2
2
|
module Models
|
3
3
|
autoload :MailingList, 'smailer/models/mailing_list'
|
4
4
|
autoload :MailCampaign, 'smailer/models/mail_campaign'
|
5
|
+
autoload :MailCampaignAttachment, 'smailer/models/mail_campaign_attachment'
|
5
6
|
autoload :MailKey, 'smailer/models/mail_key'
|
6
7
|
autoload :QueuedMail, 'smailer/models/queued_mail'
|
7
8
|
autoload :FinishedMail, 'smailer/models/finished_mail'
|
@@ -10,6 +10,8 @@ module Smailer
|
|
10
10
|
belongs_to :mailing_list
|
11
11
|
has_many :queued_mails, :dependent => :destroy
|
12
12
|
has_many :finished_mails, :dependent => :destroy
|
13
|
+
has_many :attachments,
|
14
|
+
:class_name => '::Smailer::Models::MailCampaignAttachment'
|
13
15
|
|
14
16
|
validates_presence_of :mailing_list_id, :from
|
15
17
|
validates_numericality_of :mailing_list_id, :unsubscribe_methods, :only_integer => true, :allow_nil => true
|
@@ -48,6 +50,10 @@ module Smailer
|
|
48
50
|
opened_mails_count.to_f / sent_mails_count
|
49
51
|
end
|
50
52
|
|
53
|
+
def add_attachment(filename, path)
|
54
|
+
self.attachments.create!(:filename => filename, :path => path)
|
55
|
+
end
|
56
|
+
|
51
57
|
def self.unsubscribe_methods
|
52
58
|
methods = {}
|
53
59
|
UnsubscribeMethods.constants.map do |method_name|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
module Smailer
|
4
|
+
module Models
|
5
|
+
class MailCampaignAttachment < ActiveRecord::Base
|
6
|
+
|
7
|
+
belongs_to :mail_campaign
|
8
|
+
validates_presence_of :mail_campaign_id
|
9
|
+
validates_numericality_of :mail_campaign_id
|
10
|
+
validates_presence_of :path
|
11
|
+
validates_presence_of :filename
|
12
|
+
|
13
|
+
def body
|
14
|
+
open(self.path).read
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/smailer/tasks/send.rb
CHANGED
@@ -53,12 +53,21 @@ module Smailer
|
|
53
53
|
Smailer::Models::QueuedMail.update_all(lock_update, lock_condition)
|
54
54
|
end
|
55
55
|
|
56
|
+
# map of attachment ID to contents - so we don't keep opening files
|
57
|
+
# or URLs
|
58
|
+
cached_attachments = {}
|
59
|
+
|
56
60
|
items_to_process.each do |queue_item|
|
57
61
|
# try to send the email
|
58
62
|
mail = Mail.new do
|
59
63
|
from queue_item.from
|
60
64
|
to queue_item.to
|
61
65
|
subject queue_item.subject
|
66
|
+
queue_item.mail_campaign.attachments.each do |attachment|
|
67
|
+
cached_attachments[attachment.id] ||= attachment.body
|
68
|
+
add_file :filename => attachment.filename,
|
69
|
+
:content => cached_attachments[attachment.id]
|
70
|
+
end
|
62
71
|
|
63
72
|
text_part { body queue_item.body_text }
|
64
73
|
html_part { body queue_item.body_html; content_type 'text/html; charset=UTF-8' }
|
data/lib/smailer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitar Dimitrov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- lib/smailer/models.rb
|
76
76
|
- lib/smailer/models/finished_mail.rb
|
77
77
|
- lib/smailer/models/mail_campaign.rb
|
78
|
+
- lib/smailer/models/mail_campaign_attachment.rb
|
78
79
|
- lib/smailer/models/mail_key.rb
|
79
80
|
- lib/smailer/models/mailing_list.rb
|
80
81
|
- lib/smailer/models/property.rb
|