通过本地主机向ROR应用中的注册用户发送确认电子邮件 [英] Sending confirmation emails to registered users in ROR app via localhost

查看:112
本文介绍了通过本地主机向ROR应用中的注册用户发送确认电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的ROR应用中,我正在尝试向注册用户注册时发送确认电子邮件,我的网站当前位于本地主机上.我收到此错误:

In my ROR app, I am trying to send confirmation emails to my registered users when they signup, my website is on localhost currently. I am getting this error:

"undefined method `recipients' for #<UserMailer:0x3d841a0>"

这是我的代码;

development.rb

config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => "localhost:3000"}
config.action_mailer.smtp_settings = {
      :address      => "smtp.gmail.com",
      :port          => "587",
      :authentication => :login,
      :user_name      => "myemailid@gmail.com",
      :password       => "myrealpassword"
}  

Users_controller.rb

def new
  UserMailer.registration_confirmation(@user).deliver
end

def create
  @user = User.new(params[:user])
  if @user.save
    UserMailer.registration_confirmation(@user).deliver
    sign_in @user
    flash[:success] = "Welcome!"
    redirect_to @user
  else
    render 'new'
  end
end

user_mailer.rb

class UserMailer < ActionMailer::Base   
  def registration_confirmation(user)
    recipients   user.email
    from         "myemailid@gmail.com"
    subject      "Thank you for registration"
    body         :user => user  
  end
end

推荐答案

** development.rb **

config.action_mailer.delivery_method = :sendmail
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true

** Users_controller.rb **

def new
  UserMailer.registration_confirmation(@user).deliver
end
def create
  @user = User.new(params[:user])
  if @user.save
    UserMailer.registration_confirmation(@user).deliver
    sign_in @user
    flash[:success] = "Welcome!"
    redirect_to @user
  else
    render 'new'
  end
end

** User_mailer.rb **

 def registration_confirmation(user) 
   @message = 'whatever you want to say here!'
   mail(:from => "myemailid@gmail.com", :to => user.email, :subject => "Thank you for registration")
end

**/app/views/user_mailer/registration_confirmation.text.erb *

<%= @message %>

这就是我在开发模式下完成的工作,并且有效

That's what I've done in my development mode, and it works

这篇关于通过本地主机向ROR应用中的注册用户发送确认电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆