我試圖在rails中使用郵件程序和sendgrid建立聯繫表單。我在Heroku上運行應用程序。電子郵件沒有到達 - Rails,Heroku,Sendgrid
我認爲開發和生產配置文件是好的,因爲我使用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: '[email protected]', 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' }
不,我試過你的建議,但沒有成功。我真的不知道該怎麼做。一切似乎都沒問題,但沒有電子郵件到達 –
您是否可以複製並粘貼您的heroku日誌的輸出? 順便說一下,檢查爲Sendgrid設置的heroku憑證。在您的heroku面板中,我認爲是:「設置」,然後單擊「顯示配置變量」。 只是爲了確保您擁有正確的憑據。 –