如何配置动作邮件程序(我应该注册域名)?
我正在使用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帐户,如何填充上面的设置? 我是否需要购买域名,可以从谷歌购买以使用上述设置?
- 在我的电脑上设置邮件服务器更好吗? 我看了这个教程,但据我了解,我仍然需要购买域名。
另外,正如这里所说:
设置电子邮件服务器是一个困难的过程,涉及许多不同的程序,每个程序都需要正确配置。
因为这和我的技能不佳,我正在寻找最简单的解决方案。
我已经阅读了rails action mailer 教程并了解了这些参数的用途,但Gmail和邮件服务器周围的内容根本不清楚。
应该/可以在development
和production
定义邮件程序的配置此配置的目的是当您使用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
所以这里发生的是当使用create
动作时,它会激活邮件程序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' }
这应该是一个足够彻底的解释,以启动你正确的方向。
一旦我改变它,上面的答案对我有用
authentication: 'plain'
并包括在内
config.action_mailer.raise_delivery_errors = true
在我的开发环境中。