ActionMailer::Base.raise_delivery_errors = true
begin
    ActionMailer::Base.delivery_method = GenericState.allow_emails? ? :smtp : :test
rescue
    # this can happen on the build server when it's compiling assets and doesn't have the 'jam' database
    ActionMailer::Base.delivery_method = :test
end
ActionMailer::Base.smtp_settings = {
    :address        => Rails.application.config.email_smtp_address,
    :port           => Rails.application.config.email_smtp_port,
    :domain         => Rails.application.config.email_smtp_domain,
    :authentication => Rails.application.config.email_smtp_authentication,
    :user_name      => Rails.application.config.email_smtp_user_name,
    :password       => Rails.application.config.email_smtp_password ,
    :enable_starttls_auto => Rails.application.config.email_smtp_starttls_auto
}

Rails.logger.debug("ActionMailer.delivery_method = #{ActionMailer::Base.delivery_method}")

#SendgridToolkit.api_user = Rails.application.config.sendgrid_username
#SendgridToolkit.api_key = Rails.application.config.sendgrid_password