2012-09-04 61 views
0

類似的問題 Rails contact form not workingRuby on Rails的 - 而不是發展方式發送電子郵件

指南:https://github.com/thomasklemm/email_form_rails 軌3.2.x中

應用程序\型號\ message.rb

class Message 
    include ActiveAttr::Model 
    include ActiveModel::Validations 

    attribute :name 
    attribute :email 
    attribute :subject 
    attribute :body 
    attr_accessible :name, :email, :subject, :body 

    validates_presence_of :name 
    validates_presence_of :email 
    validates :email, email_format: { message: "is not looking like a valid email address"} 
    validates_presence_of :subject 
    validates_length_of :body, maximum: 500 
end 

應用程序\寄件人\ contact_form.rb

class ContactForm < ActionMailer::Base 
    default from: "[email protected]" 
    default to: "[email protected]" 

    def email_form(message) 
    @message = message 
    mail subject: "#{message.subject} #{message.name}" 
    mail body: "#{message.body}" 
    end 
end 

development.rb

config.action_mailer.delivery_method = :smtp 
    config.action_mailer.perform_deliveries = true 
    config.action_mailer.smtp_settings = { 
     :address    => "smtp.gmail.com", 
     :port     => 587, 
     :domain    => "mydomain.com", 
     :user_name   => "[email protected]", 
     :password    => "mypassword", 
     :authentication  => :plain, 
     :enable_starttls_auto => true 
    } 

    config.action_mailer.default_url_options = { 
     :host => "localhost:3000" 
    } 

在命令輸出

開始POST爲127.0.0.1 「/電子郵件」 在2012年9月4日22時10分四十秒0700 處理通過的HomeController#send_email_form如HTML參數 {「utf8」=>「√」,「authenticity_token」=>「w39BLqCrjTMm4RRi/Sm5hZoEpcw46 npyRy/RS0h48x0 =」,「message」=> {「name」=>「anonymousxxx」, 「email」= >「[email protected]」,「subject」=>「Test」,「body」=>「send email」},「commit」=>「Create Message」}重定向到 本地主機:完成302 3000 /首頁/聯繫發現在1毫秒 (ActiveRecord的:0.0ms)

但電子郵件(消息)沒收到我的電子郵件,..

回答

0

如果日誌說的是Completed開發模式,它不會告訴郵件發送。您需要在config/environment/development.rb中設置config.action_mailer.raise_delivery_errorstrue值,如果電子郵件發送不正確,它將顯示一些錯誤。

Rails.application.configure do 
    ## other stuff 
    config.action_mailer.raise_delivery_errors = true 
    ## other stuff 
end 
1

如果你只希望看到的電子郵件被觸發,有一種方法可以使用動作郵件程序配置傳送方法將電子郵件保存到本地文件系統,並指定要保存的位置。我通常保存到tmp/mail。

相關問題