如何配置我的服务器从Ruby on Rails发送电子邮件

时间:2015-01-14 22:55:54

标签: ruby-on-rails actionmailer

我正在使用Rails附带的服务器,我需要将其配置为向收件人发送电子邮件,例如juan@gmail.com和pepe@hotmail.com。

我是否需要使用我的Gmail帐户或安装本地SMTP服务。我是铁轨上的红宝石新手

我正在使用Mailers执行此操作。

我在互联网上看到的一个例子如下。

ActionMailer::Base.smtp_settings = {
  :user_name => 'your_sendgrid_username',
  :password => 'your_sendgrid_password',
  :domain => 'yourdomain.com',
  :address => 'smtp.sendgrid.net',
  :port => 587,
  :authentication => :plain,
  :enable_starttls_auto => true
} 

2 个答案:

答案 0 :(得分:1)

要从本地发送邮件,请将以下代码放入config / application.rb

config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = {
      :address              => "smtp.gmail.com",
      :port                 => 587,
      :domain               => 'gmail.com',
      :user_name            => 'your_email_id',
      :password             => 'password',
      :authentication       => 'plain',
      :enable_starttls_auto => true  }

在application.rb文件中添加以下行...

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

答案 1 :(得分:0)

要从本地发送邮件,请将以下代码放入config / environments / development.rb

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address:              'smtp.gmail.com',
  port:                 587,
  domain:               'example.com',
  user_name:            '<your gmail username>',
  password:             '<and its password>',
  authentication:       'plain',
  enable_starttls_auto: true  }

参考:http://guides.rubyonrails.org/action_mailer_basics.html