Rails 3.2.1 actionmailer setup

I'm having difficulty setting up ActionMailer on signup:

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 "no-reply@myapp.com"

  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 = "mydump@email.com"
  end
end

I'm not getting any emails sent to my dump email in DevelopmentMailInterceptor.

Answers


gmail is anal! Is there anyway you can use a different smtp host? I think, due to overly aggressive spam detection, they will silently reject smpt requests that they consider 'potential spam'. Potential Spam in your case means emails directed to be from an address OTHER than "mail.gmail.com", which in your case is "email.com".

I think using gmail as an SMTP host for a Rails app is a loosing proposition, I use godaddy.com (smtpout.secureserver.net) for my rails apps, and have no problems.


Need Your Help

Can I share the same eclipse project on a SVN & a GIT repository simultaneously?

git svn git-svn

Can I share the same eclipse project on a SVN &amp; a GIT repository simultaneously.

Having issue while using soap4r, unable to add namespace, encoding style to soap envelope

ruby soap wsdl soap4r

I am having problems with one of the soap service I'm using. I am using soap4r for consuming the soap service. But somehow they are expecting something else than what I am sending. This is what I'm

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.