Sha256: 31328dfe063f448fb6129aa1a8e532bc7b52ac855f004a3e13ad0444c0132291

Contents?: true

Size: 1.06 KB

Versions: 12

Compression:

Stored size: 1.06 KB

Contents

require 'net/smtp'

class Eye::Notify::Mail < Eye::Notify

  # Eye.config do
  #   mail :host => "some.host", :port => 12345, :user => "eye@some.host", :password => "123456", :domain => "some.host"
  #   contact :vasya, :mail, "vasya@some.host"
  # end

  param :host, String, true
  param :port, [String, Fixnum], true

  param :domain, String
  param :user, String
  param :password, String
  param :auth, Symbol, nil, nil, [:plain, :login, :cram_md5]

  param :from_mail, String
  param :from_name, String, nil, 'eye'

  def execute
    smtp
  end

  def smtp
    args = [host, port, domain, user, password, auth]
    debug "called smtp with #{args}"

    Net::SMTP.start(*args) do |smtp|
      smtp.send_message(message, from_mail || user, contact)
    end
  end

  def message
    h = []
    h << "From: #{from_name} <#{from_mail || user}>" if from_mail || user
    h << "To: <#{contact}>"
    h << "Subject: #{message_subject}"
    h << "Date: #{msg_at.httpdate}"
    h << "Message-Id: <#{rand(1000000000).to_s(36)}.#{$$}.#{contact}>"
    "#{h * "\n"}\n#{message_body}"
  end

end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
reel-eye-0.5.2.1 lib/eye/notify/mail.rb
reel-eye-0.5.2 lib/eye/notify/mail.rb
eye-0.5.2 lib/eye/notify/mail.rb
reel-eye-0.5.1 lib/eye/notify/mail.rb
eye-0.5.1 lib/eye/notify/mail.rb
reel-eye-0.5 lib/eye/notify/mail.rb
eye-0.5 lib/eye/notify/mail.rb
eye-0.4.2 lib/eye/notify/mail.rb
reel-eye-0.4.1 lib/eye/notify/mail.rb
eye-0.4.1 lib/eye/notify/mail.rb
reel-eye-0.4 lib/eye/notify/mail.rb
eye-0.4 lib/eye/notify/mail.rb