Commit 2a17c68c authored by Andi Saurer's avatar Andi Saurer

send email on failure

parent 7ee70070
module ShortMessage
class Mailer < ActionMailer::Base
default from: ShortMessage.config.default_mail_sender
def recharge_notification amount
mail to: ShortMessage.config.reload_notification_email, :from => ShortMessage.config.default_mail_sender, :subject => "SMS credit recharged", :body => "Your SMS Account has automatically been recharged with #{amount} sms."
mail to: ShortMessage.config.reload_notification_email, :subject => "SMS credit recharged", :body => "Your SMS Account has automatically been recharged with #{amount} sms."
end
def voucher_notification amount
mail :to => ShortMessage.config.voucher_notification_email, :from => ShortMessage.config.default_mail_sender, :subject => "SMS credit recharged, please create a voucher", :body => "Please add a voucher:\r\nCustomer: #{ShortMessage.config.user_id}\r\nAmount: #{amount} sms\r\n\r\nThank you!"
mail :to => ShortMessage.config.voucher_notification_email, :subject => "SMS credit recharged, please create a voucher", :body => "Please add a voucher:\r\nCustomer: #{ShortMessage.config.user_id}\r\nAmount: #{amount} sms\r\n\r\nThank you!"
end
def recharge_failed_notification amount, message
mail :to => ShortMessage.config.reload_notification_email, :from => ShortMessage.config.default_mail_sender, :subject => "SMS credit recharge failed", :body =>"SMS account could not be recharged with #{amount} sms. Error: #{body}"
mail :to => ShortMessage.config.reload_notification_email, :subject => "SMS credit recharge failed", :body =>"SMS account could not be recharged with #{amount} sms. Error: #{body}"
end
def error_notification message, response
mail :to => ShortMessage.config.reload_notification_email, :subject => "Error delivering SMS to #{message.recipient}", :body =>"SMS from #{message.sender} to #{message.recipient} could not be sent!\r\n\r\nResponse: #{response.to_yaml}"
end
end
end
......@@ -37,6 +37,7 @@ module ShortMessage
self.save
true
else
Mailer.error_notification(self, response).deliver unless ShortMessage.config.admin_notification_email.blank?
false
end
end
......
......@@ -14,6 +14,7 @@ ShortMessage.configure do |config|
config.default_mail_sender = "webmaster@your-domain.com"
config.reload_notification_email = "webmaster@your-domain.com"
config.admin_notification_email = "webmaster@your-domain.com" # set to blank to deactivate error mailing
config.voucher_notification_email = "give-me-money@your-domain.com" # set nil to disable voucher mailing
# set a default sms sender (used if no sender is present)
......
......@@ -4,35 +4,36 @@ module ShortMessage
def self.configure(&block)
yield @config ||= ShortMessage::Configuration.new
end
def self.config
@config
end
class Configuration #:nodoc:
include ActiveSupport::Configurable
config_accessor :gateway_server
config_accessor :gateway_port
config_accessor :send_file_path
config_accessor :account_functions_path
config_accessor :user_id
config_accessor :ccu_id
config_accessor :id_string
config_accessor :default_sms_sender
config_accessor :default_reload_amount
config_accessor :reload_notification_email
config_accessor :admin_notification_email
config_accessor :voucher_notification_email
config_accessor :default_mail_sender
def param_name
config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name
end
# define param_name writer (copied from AS::Configurable)
writer, line = 'def param_name=(value); config.param_name = value; end', __LINE__
singleton_class.class_eval writer, __FILE__, line
class_eval writer, __FILE__, line
end
end
\ No newline at end of file
end
module ShortMessage
VERSION = "0.0.6"
VERSION = "0.1.0"
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment