ruby-on-rails – 如何配置动作邮件程序(我应该注册域名)?
我正在使用
Ruby on Rails创建一个简单的非营利性应用程序.我必须设置以下设置才能通过Gmail发送电子邮件:
Depot::Application.configure do config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address:"smtp.gmail.com",port:587,domain:"domain.of.sender.net",authentication: "plain",user_name:"dave",password:"secret",enable_starttls_auto: true } end 我对这些东西全新,并且不知道我应该做什么. >如果我有Gmail帐户,如何填充上面的设置?我 另外,正如here所说:
因为这和我的技能不佳,我正在寻找最简单的解决方案. 我已经阅读了rails动作邮件程序tutorial,并了解这些参数的用途,但Gmail和邮件服务器周围的事情根本不清楚. 解决方法
应该/可以在开发和生产中定义邮件程序的配置此配置的目的是当您在使用actionmailer时设置它时,将使用这些SMTP选项.你可以有一个简单的邮件,如下所示:
信封 class UserMailer < ActionMailer::Base default :from => DEFAULT_FROM def registration_confirmation(user) @user = user @url = "http://portal.herokuapp.com/login" mail(:to => user.email,:subject => "Registered") end end 调节器 def create @title = 'Create a user' @user = User.new(params[:user]) if @user.save UserMailer.registration_confirmation(@user).deliver redirect_to usermanagement_path flash[:success] = 'Created successfully.' else @title = 'Create a user' render 'new' end end 所以这里发生的是当使用创建动作时,它会激活邮件程序UserMailer查看上面的UserMailer,它使用ActionMailer作为基础.遵循下面显示的SMTP设置,可以在config / environments / production.rb和development.rb中定义 您将拥有以下内容: config.action_mailer.default_url_options = { :host => 'portal.herokuapp.com' } config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => 'smtp.gmail.com',:port => 587,:domain => 'gmail.com',:user_name => 'EMAIL_ADDRESS@gmail.com',:password => 'pass',:authentication => 'login',:enable_starttls_auto => true } 如果要在开发模式下定义SMTP设置,则需要替换 config.action_mailer.default_url_options = { :host => 'portal.herokuapp.com' } 同 config.action_mailer.default_url_options = { :host => 'IP ADDRESS HERE:3000' } 这应该是一个足够彻底的解释,以启动你正确的方向. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |