2016-07-14 82 views
0

我试图通过实施行动邮件中相关的代码导轨发送邮件..行动邮件错误提供电子邮件

我邮寄/ user_mailer.rb

  class UserMailer < ActionMailer::Base 
    default :from => "[email protected]" 
    def registration_confirmation(user) 
     mail(:to=>user.email, :subject =>"Registered") 
     end 
     end 

users.controller是

def create 
    @user = User.new(user_params) 
     respond_to do |format| 
    if @user.save 
    UserMailer.registration_confirmation(@user).deliver 
     format.html { redirect_to @user, notice: 'User was successfully created.' } 
     format.json { render :show, status: :created, location: @user } 
     else 
    format.html { render :new } 
    format.json { render json: @user.errors, status: :unprocessable_entity } 
    end 
    end 
    end 

此处,您的初始化程序\ setup_mail.rb设置将转到development.rb

config.action_mailer.default_url_options = { host: 'localhost', port: 9292 } 

    config.action_mailer.delivery_method = :smtp 
     config.action_mailer.smtp_settings = { 
     :address  =>"smtp.thejaingroup.com", 
     :domain  =>"thejaingroup.com", 
     :port  => 587, 
     :user_name =>"[email protected]", 
     :password =>"************" 
     :authentication =>"plain" 
     } 

和我的看法是.. user_registration.text.erb ---是

  Hi sir you successfully Completed signed..........! 

我有错误味精运行此版本之后.. SocketError在UsersController#创建 的getaddrinfo:请求的名称有效,但没有找到所请求类型的数据。

+0

问题是连接smtp服务器。应用程序无法连接服务器。 –

回答

0

我不认为你在这里使用的地址'smtp.thejaingroup.com'是有效的电子邮件服务提供商的地址。如果你正在尝试使用你的Gmail,那么它应该是'smtp.gmail.com'。

这是正常的gmail配置。

config.action_mailer.smtp_settings = { 
    :address    => "smtp.gmail.com", 
    :port     => 587, 
    :user_name   => ENV['gmail_username'], 
    :password    => ENV['gmail_password'], 
    :authentication  => "plain", 
:enable_starttls_auto => true 
} 

在这种情况下,所有的邮件将被传递到您的Gmail。 。如果你不希望发生这种情况,你可以尝试gem letter_opener的开发环境。对于生产env,您可能必须使用电子邮件提供程序,例如mandrill或sendgrid。