Class: Inkcite::Mailer
- Inherits:
-
Object
show all
- Defined in:
- lib/inkcite/mailer.rb
Defined Under Namespace
Classes: Base, MailgunMailer, SmtpMailer
Class Method Summary
collapse
Class Method Details
.client(email, opts) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/inkcite/mailer.rb', line 7
def self.client email, opts
count = increment(email, :preview)
recipients = email.config[:recipients]
to = recipients[:clients] || recipients[:client]
if count == 1
also_to = recipients[FIRST_PREVIEW]
to = [* also_to] unless also_to.blank?
end
cc = recipients[:internal]
self.send(email, opts.merge({
:to => to,
:cc => cc,
:bcc => true,
:tag => "Preview ##{count}"
}))
end
|
.developer(email, opts) ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/inkcite/mailer.rb', line 39
def self.developer email, opts
count = increment(email, :developer)
self.send(email, opts.merge({
:tag => "Developer Test ##{count}"
}))
end
|
.internal(email, opts) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/inkcite/mailer.rb', line 49
def self.internal email, opts
recipients = email.config[:recipients]
count = increment(email, :internal)
self.send(email, opts.merge({
:to => recipients[:internal],
:bcc => true,
:tag => "Internal Proof ##{count}"
}))
end
|
.send(email, opts) ⇒ Object
Sends each version of the provided email with the indicated options.
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/inkcite/mailer.rb', line 65
def self.send email, opts
also_to = opts[:also]
opts[:cc] = [*opts[:cc]] + also_to unless also_to.blank?
versions = Array(opts[:version] || email.versions)
mailer_base = nil
if config = email.config[:mailgun]
mailer_base = MailgunMailer.new
elsif config = email.config[:smtp]
mailer_base = SmtpMailer.new
else
abort <<-USAGE.strip_heredoc
Oops! Inkcite can't send this email because of a configuration problem.
Please update the mailgun or smtp sections of your config.yml file.
smtp:
host: 'smtp.gmail.com'
port: 587
domain: 'yourdomain.com'
username: ''
password: ''
from: 'Your Name <[email protected]>'
Or send via Mailgun:
mailgun:
api-key: 'key-your-api-key'
domain: 'mg.sending-domain.com'
from: 'Your Name <[email protected]>'
USAGE
end
versions.each do |version|
view = email.view(:preview, :email, version)
tag = opts[:tag]
subject = view.subject
subject = "#{subject} (#{tag})" unless tag.blank?
puts "Sending '#{subject}' ..."
mailer_base.send! config, view, subject, opts
end
end
|