diaspora/lib/messagebus/mailer.rb
Jonne Haß 2a4db54db9 New configuration system
* Throw away old system
* Add new system
* Add new example files
* Replace all calls
* add the most important docs
* Add Specs
* rename disable_ssl_requirement to require_ssl
* cloudfiles isn't used/called in our code
* since community_spotlight.list is only used as enable flag replace it with such one and remove all legacy and irelevant codepaths around it
* die if session secret is unset and on heroku
* First basic infrastructure for version information
2012-09-26 20:19:37 +02:00

40 lines
1 KiB
Ruby

module Messagebus
class Mailer
def initialize(api_key)
@client = MessagebusApi::Messagebus.new(api_key)
end
attr_accessor :settings
def new(*settings)
self.settings = {}
self
end
def from_header_parse(string)
string.split('<')[0].delete('"')
end
def deliver(message)
deliver!(message)
end
def deliver!(message)
msg = {:toEmail => message.to.first, :subject => message.subject, :fromEmail => AppConfig.mail.sender_address, :fromName => from_header_parse(message[:from].to_s)}
if message.multipart?
msg[:plaintextBody] = message.text_part.body.to_s if message.text_part
msg[:htmlBody] = message.html_part.body.to_s if message.html_part
else
msg[:plaintextBody] = message.body.to_s
msg[:htmlBody] = message.body.to_s
end
begin
@client.add_message(msg, true)
rescue => message_bus_api_error
raise "Messagebus API error=#{message_bus_api_error}, message=#{msg.inspect}"
end
end
end
end