class SipoMailer::Mailer

Public Class Methods

new(to:, from:, subject:, attachment: nil) click to toggle source
# File lib/sipo_mailer/email.rb, line 21
def initialize(to:, from:, subject:, attachment: nil)
  @to         = to
  @from       = from
  @subject    = subject
  @attachment = attachment
end
send(to: 'landovsky@gmail.com', from: SipoMailer.config.yaml.dig(:email, :address), subject: 'ahoj', attachment: nil) click to toggle source
# File lib/sipo_mailer/email.rb, line 28
def self.send(to: 'landovsky@gmail.com',
              from: SipoMailer.config.yaml.dig(:email, :address),
              subject: 'ahoj',
              attachment: nil)
  email = new(to: to, from: from, subject: subject, attachment: attachment)
  begin
    response = email.send
    Response.new(response)
  rescue DeliveryError => e
    p e
  end
end

Public Instance Methods

email() click to toggle source
# File lib/sipo_mailer/email.rb, line 57
def email
  email         = Mail.new
  email.to      = @to
  email.from    = @from
  email.subject = @subject
  email.body    = email_body
  email.add_file(@attachment.path) if @attachment
  email
end
send() click to toggle source
# File lib/sipo_mailer/email.rb, line 41
def send
  email.deliver!
rescue SocketError
  print "\n\nChyba při posílání emailu: adresa " \
    "#{Mail.delivery_method.settings[:address]} není dostupná.\n"
  exit
rescue Net::SMTPAuthenticationError
  print "\n\nChyba při posílání emailu: " \
    "chybné přihlašovací údaje pro emailovou schránku.\n"
  exit
rescue Net::OpenTimeout
  print "\n\nChyba při posílání emailu: vypršel časový limit "\
    "při spojení s emailovým serverem.\n"
  exit
end

Private Instance Methods

email_body() click to toggle source
# File lib/sipo_mailer/email.rb, line 69
def email_body
  'something simple'
end