2016-07-14 33 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。