Class: Postal::SendRawMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/postal/send_raw_message.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ SendRawMessage

Returns a new instance of SendRawMessage.


7
8
9
10
# File 'lib/postal/send_raw_message.rb', line 7

def initialize(client)
  @client = client
  @attributes = {}
end

Instance Method Details

#data(data) ⇒ Object


32
33
34
# File 'lib/postal/send_raw_message.rb', line 32

def data(data)
  @attributes[:data] = Base64.encode64(data)
end

#mail_from(address) ⇒ Object


23
24
25
# File 'lib/postal/send_raw_message.rb', line 23

def mail_from(address)
  @attributes[:mail_from] = address
end

#rcpt_to(*addresses) ⇒ Object


27
28
29
30
# File 'lib/postal/send_raw_message.rb', line 27

def rcpt_to(*addresses)
  @attributes[:rcpt_to] ||= []
  @attributes[:rcpt_to] += addresses
end

#send!Object


12
13
14
15
16
17
18
19
20
21
# File 'lib/postal/send_raw_message.rb', line 12

def send!
  api = @client.moonrope.request(:send, :raw, @attributes)
  if api.success?
    SendResult.new(@client, api.data)
  elsif api.status == 'error'
    raise SendError.new(api.data['code'], api.data['message'])
  else
    raise Error, "Couldn't send message"
  end
end