簡體   English   中英

有沒有辦法在heroku上使用sendgrid調試郵件程序? 或者檢查郵件是否實際發送?

[英]Is there a way to debug mailer with sendgrid on heroku? Or to check if the mail get actually sent?

我正在嘗試在rails 3.0.10項目上實現“聯系我們”表單。 在RailsGuides之后,我創建了一個郵件程序。

class QuestionMailer < ActionMailer::Base
  default :to => "%mail@mydomain" #gmail for domains

  def ask(message)
    @content = message.content

    unless message.name.nil? or message.name.empty?
      from = "#{message.name} <#{message.email}>"
    else
      from = message.email
    end

    mail(:subject => message.subject, :from => from)
  end
end

在我的控制器中,我有這些線:

if @question.valid?
  QuestionMailer.ask(@question).deliver
  redirect_to root_url, :notice => "Сообщение отправлено"
else

Production.rb:

config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => '%mydomain%' }

ActionMailer::Base.smtp_settings = {
  :address        => "smtp.sendgrid.net",
  :port           => "25",
  :authentication => :plain,
  :user_name      => ENV['SENDGRID_USERNAME'],
  :password       => ENV['SENDGRID_PASSWORD'],
  :domain         => ENV['SENDGRID_DOMAIN']
}

我一開始沒有這個配置,但是當我沒有收到電子郵件時,我添加了它。

問題是,Heroku日志說,相應的視圖已經呈現,但我沒有收到電子郵件。 因為我使用sendgrid,我無法在本地測試它。

UPD

注意自我。 為域帳戶創建Gmail后,請不要忘記您的DNS設置。 > _ <

您仍然可以使用sendgrid進行本地測試 - 從命令行執行heroku config ,您可以獲取Heroku為sendgrid用戶名,密碼和域設置的值,然后將它們與actionsmailer設置一起設置在development.rb中,它將路由您從本地開發應用程序通過sendgrid發送的消息。

我還發現這個heroku插件https://github.com/hone/heroku-sendgrid-stats對於檢查我的消息發送號碼非常有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM