2013-12-20 3 views
0

제출 한 양식에 내용을 기입 한 이메일을 발송하는 양식을 만들었습니다. 때로는 이메일이 전송되고 때로는 그렇지 않은 이유는 무엇입니까?내 이메일 양식이 이메일을 보내는 이유는 무엇입니까?

notifcations_mailer.rb 

class NotificationsMailer < ActionMailer::Base 
    default :from => "[email protected]" 
    default :to => "[email protected]" 

    def new_message(message) 
    @message = message 
    mail(:subject => "Appointment for #{message.date}") 
    end 
end 

contact_controller.rb

class ContactController < ApplicationController 

def new 
    @message = Message.new 
end 

def create 
    @message = Message.new(params[:message]) 

    if @message.valid? 
    NotificationsMailer.new_message(@message).deliver 
    redirect_to(contact_path, :notice => "Message was successfully sent.") 
    else 
    flash.now.alert = "Please fill all fields." 
    redirect_to :back 
    end 
end 
end 

message.rb :

class Message 

include ActiveModel::Validations 
include ActiveModel::Conversion 
extend ActiveModel::Naming 

attr_accessor :name, :currentpatient, :email, :phone, :calltime, :date, :apttime, :treatment, :subject 

validates :name, :currentpatient, :phone, :calltime, :date, :apttime, :treatment, :presence => true 
validates_format_of :email, :with => /[email protected]+\..+/i 

def initialize(attributes = {}) 
    attributes.each do |name, value| 
    send("#{name}=", value) 
end 
end 

def persisted? 
    false 
end 
end 

application.rb :

config.action_mailer.smtp_settings = { 
    :address    => "smtpout.secureserver.net", 
    :port     => 80, 
    :domain    => "domain.com", 
    :user_name   => "[email protected]", 
    :password    => "mypass", 
    :authentication  => :plain, 
    :enable_starttls_auto => true 
} 

config.action_mailer.default_url_options = { 
    :host => "domain.com" 
} 

Heroku가 로그 (이메일이 시간이 전송되지 않았습니다)

당신은 구성을 누락 16,
2013-12-20T06:28:54.321446+00:00 app[web.1]: Started POST "/contact" for 67.174.151.10 at   2013-12-20 06:28:54 +0000 
2013-12-20T06:28:54.335613+00:00 app[web.1]: Completed 302 Found in 8ms (ActiveRecord: 0.0ms) 
2013-12-20T06:28:54.335613+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"36gs7HfnaIbH0003rYZ+6mC3sFE36ut8iHHiBZgSAlo=", "message"=>{"name"=>"Eric Filkins", "email"=>"[email protected]", "phone"=>"8675309", "calltime"=>"Morning", "date"=>"Chrome test", "apttime"=>"Morning", "treatment"=>"Dream Smiles"}, "commit"=>"Submit"} 
2013-12-20T06:28:54.335613+00:00 app[web.1]: Processing by ContactController#create as HTML 
2013-12-20T06:28:54.335613+00:00 app[web.1]: Redirected to http://www.tlcdentalsyr.com/contact 
2013-12-20T06:28:54.339538+00:00 heroku[router]: at=info method=POST path=/contact host=www.tlcdentalsyr.com fwd="67.174.151.10" dyno=web.1 connect=1ms service=22ms status=302 bytes=101 
2013-12-20T06:28:54.440927+00:00 app[web.1]: Started GET "/contact" for 67.174.151.10 at 2013-12-20 06:28:54 +0000 
2013-12-20T06:28:54.496993+00:00 app[web.1]: Processing by StaticPagesController#contact as HTML 
2013-12-20T06:28:54.496993+00:00 app[web.1]: Completed 200 OK in 50ms (Views: 50.0ms | ActiveRecord: 0.0ms) 
2013-12-20T06:28:54.496993+00:00 app[web.1]: Rendered static_pages/contact.html.erb within layouts/application (39.8ms) 

답변

2

는 production.rb 파일 설정 아래에 보라

#default url for mailer 
config.action_mailer.default_url_options = { :host => 'domainname' } 
config.action_mailer.delivery_method = :smtp 
config.action_mailer.perform_deliveries = true 
config.action_mailer.raise_delivery_errors = false 
config.action_mailer.default :charset => "utf-8" 

config.action_mailer.smtp_settings = { 
:enable_starttls_auto => false, 
:address => "smtp.emailsrvr.com", 
:port => 587, 
:domain => "domainname", 
:authentication => :login, 
:user_name => '[email protected]', 
:password => 'password', 
} 

해피 코딩. !!

관련 문제