如何配置动作邮件程序(我应该注册域名)?

got*_*tqn 8 ruby ruby-on-rails actionmailer ruby-on-rails-3

我正在使用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
Run Code Online (Sandbox Code Playgroud)

我对这些东西全新,并且不知道我应该做什么.

  1. 如果我有Gmail帐户,如何填充上面的设置?我是否需要购买域名,可以从谷歌购买以使用上述设置?
  2. 在我的电脑上设置邮件服务器更好吗?我查看了 这个教程,但据我了解,我仍然需要购买域名.

另外,正如这里所说:

设置电子邮件服务器是一个困难的过程,涉及许多不同的程序,每个程序都需要正确配置.

因为这和我的技能很差,我正在寻找最简单的解决方案.

我已经阅读了rails action mailer 教程并了解了这些参数的用途,但Gmail和邮件服务器周围的事情根本不清楚.

Dav*_*vid 17

您应该/可以在两者中定义邮件程序的配置,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
Run Code Online (Sandbox Code Playgroud)

调节器

 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
Run Code Online (Sandbox Code Playgroud)

所以这里发生的是当使用create动作时,它会激活邮件程序.UserMailer查看上面的UserMailer,它使用ActionMailer作为基础.遵循下面显示的SMTP设置,可以在config/environments/production.rbdevelopment.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
  }
Run Code Online (Sandbox Code Playgroud)

如果要在开发模式下定义SMTP设置,则应替换

config.action_mailer.default_url_options = { :host => 'portal.herokuapp.com' }
Run Code Online (Sandbox Code Playgroud)

config.action_mailer.default_url_options = { :host => 'IP ADDRESS HERE:3000' }
Run Code Online (Sandbox Code Playgroud)

这应该是一个足够彻底的解释,可以帮助您朝着正确的方向前进.