Last active
August 29, 2015 14:17
-
-
Save rvgarimrj/e55a13cc22337a0dad9c to your computer and use it in GitHub Desktop.
Action Mailer Não está enviando email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($){ | |
$(document).on("click",".cancela_solicitacao",function(){ | |
$('#ModalSolicitacao').foundation('reveal', 'close'); | |
}); | |
$(document).on("click",".fecha_solicitacao",function(){ | |
$('#ModalSolicitacao').foundation('reveal', 'close'); | |
}); | |
$(document).on("click",".solicita_autorizacao",function(){ | |
solicita_autorizacao(); | |
}); | |
function solicita_autorizacao() | |
{ | |
$.ajax({ | |
type: "GET", | |
url: "/solicita_autorizacao", | |
dataType: "json", | |
data: { id_vendedor: gon.id_vendedor}, | |
complete: function() {}, | |
success: function(response) | |
{ | |
jsonData = response; | |
alert('Email enviado'); | |
} | |
}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AutorizacaoController < ApplicationController | |
def solicita_autorizacao | |
@empresa_vendedora = Empresa.find(params[:id_vendedor]) | |
AutorizacaoMailer.solicita_autorizacao(@empresa_vendedora,current_usuario) | |
# render :json => { :existe => Empresa.find_by(nome:params[:nome])} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AutorizacaoMailer < ActionMailer::Base | |
default from: "no-reply@representantevirtual.com" | |
# Subject can be set in your I18n file at config/locales/en.yml | |
# with the following lookup: | |
# | |
# en.user_mailer.signup_confirmation.subject | |
# | |
def solicita_autorizacao(empresa, usuario) | |
@empresa_vendedora = empresa | |
@empresa_compradora = usuario.empresa | |
@usuario_comprador = usuario | |
@usuario_vendedor = empresa.usuario | |
email = empresa.email | |
mail to: email, subject: "Solicitação de Autorização" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.configure do | |
config.cache_classes = false | |
Paperclip.options[:command_path] = "/usr/local/bin/convert" | |
# Do not eager load code on boot. | |
config.eager_load = false | |
config.consider_all_requests_local = true | |
config.action_controller.perform_caching = false | |
# Don't care if the mailer can't send. | |
config.action_mailer.raise_delivery_errors = true | |
config.action_mailer.perform_deliveries = true | |
config.action_mailer.delivery_method = :smtp | |
config.action_mailer.smtp_settings = { | |
:address => "smtp.gmail.com", | |
:port => 587, | |
:domain => "gmail.com", | |
:user_name => "meuemail", | |
:password => "minhasenha", | |
:authentication => 'plain', | |
:enable_starttls_auto => true } | |
# Print deprecation notices to the Rails logger. | |
config.active_support.deprecation = :log | |
# Raise an error on page load if there are pending migrations. | |
config.active_record.migration_error = :page_load | |
# Debug mode disables concatenation and preprocessing of assets. | |
# This option may cause significant delays in view rendering with a large | |
# number of complex assets. | |
config.assets.debug = true | |
# Adds additional error checking when serving assets at runtime. | |
# Checks for improperly declared sprockets dependencies. | |
# Raises helpful error messages. | |
config.assets.raise_runtime_errors = true | |
config.action_mailer.default_url_options = { host: 'localhost:3000' } | |
config.action_mailer.asset_host = 'http://localhost:3000' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DevelopmentMailInterceptor | |
def self.delivering_email(message) | |
email = 'meuemail' | |
message.to = email | |
Rails.logger.warn "Emails are sent to #{email} email account from #{Rails.env} env" | |
development_information = "[ TO: #{message.to} ]" | |
development_information << " [ CC: #{message.cc} ]" if message.cc | |
development_information << " [ BCC: #{message.bcc} ]" if message.bcc | |
message.cc = nil | |
message.bcc = nil | |
message.subject = "[Dev] #{message.subject} | |
#{development_information}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get '/solicita_autorizacao' => 'autorizacao#solicita_autorizacao', :constraints => OnlyAjaxRequest.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Started GET "/solicita_autorizacao?id_vendedor=2" for 127.0.0.1 at 2015-03-13 14:49:44 -0300 | |
Processing by AutorizacaoController#solicita_autorizacao as JSON | |
Parameters: {"id_vendedor"=>"2"} | |
Empresa Load (0.5ms) SELECT "empresas".* FROM "empresas" WHERE "empresas"."apelido" = '2' ORDER BY "empresas"."id" ASC LIMIT 1 | |
Empresa Load (0.3ms) SELECT "empresas".* FROM "empresas" WHERE "empresas"."id" = ? LIMIT 1 [["id", 2]] | |
Usuario Load (0.2ms) SELECT "usuarios".* FROM "usuarios" WHERE "usuarios"."id" = 1 ORDER BY "usuarios"."id" ASC LIMIT 1 | |
Empresa Load (0.3ms) SELECT "empresas".* FROM "empresas" WHERE "empresas"."usuario_id" = ? LIMIT 1 [["usuario_id", 1]] | |
Usuario Load (0.2ms) SELECT "usuarios".* FROM "usuarios" WHERE "usuarios"."id" = ? LIMIT 1 [["id", 2]] | |
Rendered autorizacao_mailer/solicita_autorizacao.html.erb (8.2ms) | |
AutorizacaoMailer#solicita_autorizacao: processed outbound mail in 45.0ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment