【问题标题】:How do I create a email confirmation?如何创建电子邮件确认?
【发布时间】:2012-01-23 07:10:55
【问题描述】:

我正在尝试在用户注册时发送简单的电子邮件通知。

我的用户注册工作正常,我完全按照"Sending Email" 教程进行操作,但无法使其正常工作。我做错了什么?

user_controller.rb

class Admin::UsersController < InheritedResources::Base
  before_filter :admin_only

  actions :index, :show, :new, :edit, :create, :update, :destroy
  respond_to :html

#  def new
#    @user = User.new(:invitation_token => params[:invitation_token])
#    @user.email = @user.invitation.recipient_email  
#  end  

  def create
    @user = User.new(params[:user])
    UserMailer.deliver_registration_confirmation(@user) < -- where I added the mailer
    @user.save(false)
    respond_to do |format|
      format.html{ redirect_to admin_users_path}
    end

  end

  private

  def collection
    paginate_options ||= {}
    paginate_options[:page] ||= (params[:page] || 1)
    paginate_options[:per_page] ||= (params[:per_page] || 20)
    @search = User.search(params[:search])
    @users ||= @search.all.paginate(paginate_options)
  end
end

environments/production.rb

# Settings specified here will take precedence over those in config/environment.rb
config.action_mailer.default_url_options = { :host => 'alpine.totaline.com' }

config.action_mailer.raise_delivery_errors = true

# set delivery method to :smtp, :sendmail or :test
config.action_mailer.delivery_method = :smtp

# these options are only needed if you choose smtp delivery
config.action_mailer.smtp_settings = {
  :address        => 'smtp.gmail.com',
  :port           => 25,
  :domain         => 'alpine.totaline.com',
  :authentication => :login,
  :user_name      => 'emailname@gmail.com',
  :password       => 'thepassword'
}

models/user_mailer.rb

class UserMailer < ActionMailer::Base
  def registration_confirmation(user)
    recipients  user.email
    from        "webmaster@alpinechallenge.com"
    subject     "Thank you for Registering"
    body        "You are now registered on the Alpine Challenge!"
  end  
end

【问题讨论】:

  • 你确定alp.domain..com 是对的吗?看起来不太对。
  • @Beau Grantham UserMailer.deliver_registration_confirmation(@user) - 它只是不发送电子邮件。一切看起来都设置正确
  • @Greg 是的,当我运行它时,该域已正确设置,我刚刚更改了它,我在这里发布了它,但我会仔细检查以确保
  • 为 cmets 伙计们准备的 .. 这已经很麻烦了,我无法获得简单的电子邮件确认工作.. 什么给了?!
  • 我能提供更多信息来帮助诊断问题吗?请我真的非常非常非常需要帮助

标签: ruby email registration confirmation-email email-confirmation


【解决方案1】:

对于 Gmail,您似乎需要使用端口 587:

# these options are only needed if you choose smtp delivery
config.action_mailer.smtp_settings = {
  :address        => 'smtp.gmail.com',
  :port           => '587',
  :domain         => 'alpine.totaline.com',
  :authentication => :login,
  :user_name      => 'emailname@gmail.com',
  :password       => 'thepassword'
}

This page contains notes about configuring mail clients for usage with Gmail.

【讨论】:

    猜你喜欢
    • 2011-05-13
    • 2015-11-12
    • 1970-01-01
    • 1970-01-01
    • 2019-11-23
    • 2014-11-03
    • 2017-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多