Class: Inkcite::Mailer

Inherits:
Object
  • 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

  # Determine which preview this is
  count = increment(email, :preview)

  # Get the declared set of recipients.
  recipients = email.config[:recipients]

  # Get the list of client address(es) - check both client and clients
  # as a convenience.
  to = recipients[:clients] || recipients[:client]

  # If this is the first preview, check to see if there is an
  # additional set of recipients for this initial mailing.
  if count == 1
    also_to = recipients[FIRST_PREVIEW]
    #to = [* to] + [* also_to] unless also_to.blank?
    to = [* also_to] unless also_to.blank?
  end

  # Always cc internal recipients so everyone stays informed of feedback.
  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]

  # Determine which preview this is
  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

  # Check to see if additional one-time recipients have been added
  # to the command line.
  also_to = opts[:also]
  opts[:cc] = [*opts[:cc]] + also_to unless also_to.blank?

  # Check to see if a specific version is requested or if unspecified
  # all versions of the email should be sent.
  versions = Array(opts[:version] || email.versions)

  # Will hold the instance of the Mailer::Base that will handle the
  # actual sending of the email.
  mailer_base = nil

  # Check to see if
  if config = email.config[:mailgun]
    mailer_base = MailgunMailer.new
  elsif config = email.config[:smtp]
    mailer_base = SmtpMailer.new
  else
    abort "\n      Oops! Inkcite can't send this email because of a configuration problem.\n      Please update the mailgun or smtp sections of your config.yml file.\n\n        smtp:\n          host: 'smtp.gmail.com'\n          port: 587\n          domain: 'yourdomain.com'\n          username: ''\n          password: ''\n          from: 'Your Name <[email protected]>'\n\n      Or send via Mailgun:\n\n        mailgun:\n          api-key: 'key-your-api-key'\n          domain: 'mg.sending-domain.com'\n          from: 'Your Name <[email protected]>'\n\n    USAGE\n  end\n\n  versions.each do |version|\n\n    # The version of the email we will be sending.\n    view = email.view(:preview, :email, version)\n\n    # Subject line tag such as \"Preview #3\"\n    tag = opts[:tag]\n\n    subject = view.subject\n    subject = \"\#{subject} (\#{tag})\" unless tag.blank?\n\n    puts \"Sending '\#{subject}' ...\"\n\n    mailer_base.send! config, view, subject, opts\n\n  end\n\nend\n".strip_heredoc