2012-05-02 4 views
4

У меня настройки ActionMailer на Signup трудности:Rails 3.2.1 ActionMailer установки

config/initializers/setup_mail.rb

ActionMailer::Base.smtp_settings = { 
:address    => "smtp.gmail.com", 
:port     => "587", 
:domain    => "mail.gmail.com", 
:user_name   => "my_gmail_user_name", 
:password    => "my_gmail_pw", 
:authentication  => "plain", 
:enable_starttls_auto => true 
} 

ActionMailer::Base.default_url_options[:host] = "localhost:3000" 
Mail.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development? 

users_controller.rb

def create 
    @user = User.new(params[:user]) 

    respond_to do |format| 
    if @user.save 
     UserMailer.welcome_email(@user).deliver 

     format.html{ redirect_to(@user, :notice => 'Account successfully created.') } 
     format.json{ render :xml => @user, :status => :created, :location => @user } 
    else 
     format.html { render :action => "new" } 
     format.xml { render :xml => @user.errors, :status => :unprocessable_entity } 
    end 
end 

app/mailers/user_mailer.rb

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

    def welcome_email(user) 
    @user = user 
    @url = "http://localhost:3000/login" 
    mail(:to => user.email, :subject => 'Welcome to app') 
    end 
end 

lib/development_mail_interceptor.rb

class DevelopmentMailInterceptor 
    def self.delivering_email(message) 
    message.subject = "#{message.to} #{message.subject}" 
    message.to = "[email protected]" 
    end 
end 

Я не получаю электронные письма, отправленные на мой адрес электронной почты самосвала в DevelopmentMailInterceptor.

ответ

1

gmail - это анал! В любом случае вы можете использовать другой smtp-хост? Я думаю, из-за чрезмерно агрессивного обнаружения спама они будут молча отклонять запросы smpt, которые они считают «потенциальным спамом». Потенциальный спам в вашем случае означает электронные письма, направленные на адрес OTHER, чем «mail.gmail.com», который в вашем случае является «email.com».

Я думаю, что использование gmail в качестве хоста SMTP для приложения Rails - это предложение, я использую godaddy.com (smtpout.secureserver.net) для своих приложений с рельсами и не имею проблем.

Смежные вопросы