Module: RCL::SMTP

Defined in:
lib/rcl/smtp.rb

Class Method Summary collapse

Class Method Details

.send(mta, from, from_alias, to, to_alias, subject, message) ⇒ Object

Raises:

  • (ArgumentError)


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
38
39
40
41
42
# File 'lib/rcl/smtp.rb', line 8

def self.send(mta, from, from_alias, to, to_alias, subject, message)
  raise ArgumentError, 'nil mta' if mta.nil?
  raise ArgumentError, 'invalid mta class' if mta.class != String
  raise ArgumentError, 'empty mta' if mta.empty?
  raise ArgumentError, 'nil from' if from.nil?
  raise ArgumentError, 'invalid from class' if from.class != String
  raise ArgumentError, 'empty from' if from.empty?
  raise ArgumentError, 'nil from_alias' if from_alias.nil?
  raise ArgumentError, 'invalid from_alias class' if from_alias.class \
    != String
  raise ArgumentError, 'empty from' if from_alias.empty?
  raise ArgumentError, 'nil to' if to.nil?
  raise ArgumentError, 'invalid to class' if to.class != String
  raise ArgumentError, 'empty from' if to.empty?
  raise ArgumentError, 'nil to_alias' if to_alias.nil?
  raise ArgumentError, 'invalid to_alias class' if to_alias.class != \
    String
  raise ArgumentError, 'empty from' if to_alias.empty?
  raise ArgumentError, 'nil subject' if subject.nil?
  raise ArgumentError, 'invalid subject class' if subject.class != String
  raise ArgumentError, 'nil message' if message.nil?
  raise ArgumentError, 'invalid message class' if message.class != String

  msg = <<EOM
From: #{from} <#{from_alias}>
To: #{to_alias} <#{to}>
Subject: #{subject}

#{message}
EOM

  Net::SMTP.start(mta) do |smtp|
    smtp.send_message(msg, from, to)
  end
end