电子邮件没有到达 - Rails,Heroku,Sendgrid

时间:2016-07-27 15:29:55

标签: ruby-on-rails ruby heroku

我尝试使用邮件程序和sendgrid在rails中设置联系表单。我在Heroku上运行应用程序。

我认为开发和生产配置文件没问题,因为我使用Devise进行身份验证,并且发送和接收的电子邮件没有任何问题。所以这个问题与我创建的邮件有关。

终端显示正在开发中触发电子邮件,而在生产中,heroku日志告诉我他们正在被发送。一切看起来都不错,但电子邮件还没有到货。

感谢您的反馈。

这是代码:

free_trial_form

<%= form_tag("/public_pages/contato_free_trial", :id => 'free_trail_form') do %>
        <div class="form-group">
            <%= text_field_tag :nome,nil, placeholder:"Seu nome", class: "form-control", id:"free_trail_form_nome_field" %>
        </div>
        <div class="form-group">
            <%= email_field_tag :email,nil, placeholder:"Seu e-mail", class: "form-control", id:"free_trail_form_email_field" %>
        </div>
        <div class="form-group">
            <%= text_area_tag :conteudo,nil, placeholder:"Veja na prática como é o nosso ensino. Digite aqui os horários mais confortáveis para você!", class: "form-control",id:"free_trail_form_text_area" %>
        </div>

        <div class="free_trail_form_area_btns">
            <%= button_tag(type:"submit", id: "free_trail_form_btn", class:"btn btn-danger",:onclick => "alert('Mensagem enviada. Obrigado!');") do %>
                        <span id="free_trail_form_btn_icon" class="glyphicon glyphicon-calendar"></span> 
                        MARCAR AULA GRATUITA
            <% end %>
            <%=link_to(escola_path,id:"free_trail_form_escola_link") do %>

                <button id="free_trail_form_escola_link_btn" class="btn btn-primary">
                    OU SAIBA MAIS AGORA <span id="free_trail_form_escola_link_icon" class="glyphicon glyphicon-arrow-right"></span>
                </button>
            <% end %>
        </div>
    <% end %>

public_pages_controller / contato_free_trial

def contato_free_trial
  @nome = params[:nome]
  @email = params[:email]
  @conteudo = params[:conteudo]
  PublicPagesMailer.free_trial_email(@nome,@email,@conteudo).deliver_now
  redirect_to(:back)
end

public_pages_mailer

class PublicPagesMailer < ApplicationMailer

def free_trial_email(nome,email,conteudo)
    @nome = nome
    @email = email
    @conteudo = conteudo
    mail(from: @email, to: 'contatoingleshi@gmail.com', subject: "Contato de Prospecto")
end

生产配置文件

ActionMailer::Base.smtp_settings = {
 :address => 'smtp.sendgrid.net',
 :port => '587',
 :authentication => :plain,
 :user_name => ENV['SENDGRID_USERNAME'],
 :password => ENV['SENDGRID_PASSWORD'],
 :domain => 'heroku.com',
 :enable_starttls_auto => true
}
config.cache_classes = true

config.eager_load = true

config.consider_all_requests_local       = false

config.action_controller.perform_caching = true

config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?

config.assets.js_compressor = :uglifier

config.assets.compile = true

config.assets.digest = true

config.log_level = :debug

config.i18n.fallbacks = true

config.active_support.deprecation = :notify

config.log_formatter = ::Logger::Formatter.new

config.active_record.dump_schema_after_migration = false

config.action_mailer.default_url_options = { :host => 'myapp.herokuapp.com' }

1 个答案:

答案 0 :(得分:0)

您是否确定电子邮件在生产环境中是正确的。

将以上内容添加到您的生产配置文件中的代码中,您只有第一行而不是第二行。移动上面的第一个并添加其他代码。

done()

我可以建议,使用“pry-rails”和“pry-navigation”。在发送电子邮件的方法中,您将添加config.action_mailer.default_url_options = {host: "http://yourdomain/"} config.action_mailer.delivery_method = :smtp 之类的内容,然后在您的控制台中,您将看到每一步。

您也可以提高邮件的错误。在您的生产环境中,检查您是否有类似这样的内容:binding.pry并更改为true。