Class: Antwort::CLI::Send

Inherits:
Object
  • Object
show all
Includes:
Thor::Shell
Defined in:
lib/antwort/cli/send.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(build_id, options = {}) ⇒ Send

Returns a new instance of Send.



21
22
23
24
25
26
27
28
# File 'lib/antwort/cli/send.rb', line 21

def initialize(build_id, options = {})
  @build_id  = build_id
  @html_body = File.open("build/#{build_id}/#{template_name}.html").read

  @recipient = (options[:recipient] || ENV['SEND_TO']).split(',')
  @sender    = options[:from] || ENV['SEND_FROM']
  @subject   = options[:subject] || '[Test] ' << extract_title(@html_body)
end

Instance Attribute Details

#build_idObject (readonly)

Returns the value of attribute build_id.



8
9
10
# File 'lib/antwort/cli/send.rb', line 8

def build_id
  @build_id
end

#html_bodyObject (readonly)

Returns the value of attribute html_body.



8
9
10
# File 'lib/antwort/cli/send.rb', line 8

def html_body
  @html_body
end

#mailObject (readonly)

Returns the value of attribute mail.



8
9
10
# File 'lib/antwort/cli/send.rb', line 8

def mail
  @mail
end

#recipientObject (readonly)

Returns the value of attribute recipient.



8
9
10
# File 'lib/antwort/cli/send.rb', line 8

def recipient
  @recipient
end

#senderObject (readonly)

Returns the value of attribute sender.



8
9
10
# File 'lib/antwort/cli/send.rb', line 8

def sender
  @sender
end

#subjectObject (readonly)

Returns the value of attribute subject.



8
9
10
# File 'lib/antwort/cli/send.rb', line 8

def subject
  @subject
end

Instance Method Details

#sendObject

rubocop:disable Metrics/MethodLength



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/antwort/cli/send.rb', line 31

def send
  # because scope changes inside mail DSL
  mail_from    = @sender
  mail_to      = @recipient
  mail_subject = @subject

  # setup email
  @mail = Mail.new do
    from     mail_from
    to       mail_to
    subject  mail_subject

    text_part do
      body 'This is plain text'
    end

    html_part do
      content_type 'text/html'
      body @html_body
    end
  end

  # send email
  if @mail.deliver!
    say "Sent Email \"#{template_name}\" at #{Time.now.strftime('%d.%m.%Y %H:%M')}", :green
    say "  to:      #{@recipient}"
    say "  subject: #{@subject}"
    say "  html:    #{build_id}/#{template_name}.html"
  else
    say "Error sending #{build_id}/#{template_name} at #{Time.now.strftime('%d.%m.%Y %H:%M')}", :red
  end
end