部署 mailcatcher 如何部署到生产环境?

tracyzhang · 2015年03月24日 · 最后由 tracyzhang 回复于 2015年03月24日 · 2829 次阅读

开发环境下,我在 config/environments/development.rb 里添加了如下配置

config.action_mailer.delivery_method = :smtp config.action_mailer.default_url_options = { host: 'yunmed-2015-website.dev' } #开发环境 config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }

按照http://mailcatcher.me/ 的教程我也安装了 mailcatcher。并且在开发环境可以收到邮件,并且去重置自己的密码。

但是产品上线,真正到生产环境可如何配置呢?

或者我想问,devise 的忘记密码发送邮件是如何做到的呢?

Devise 设置

# user.rb + confirmable
devise :database_authenticatable, :registerable,
        :recoverable, :rememberable, :trackable, :validatable, :confirmable
# migration
     ## Confirmable
     t.string   :confirmation_token
     t.datetime :confirmed_at
     t.datetime :confirmation_sent_at
     t.string   :unconfirmed_email # Only if using reconfirmable
     add_index :users, :confirmation_token,   unique: true
# devise.rb
 config.mailer_sender = '<your_email>'
 # Configure the class responsible to send e-mails.
 config.mailer = 'Devise::Mailer'

Mailer 设置 Gmail 设置请查看Guides

# production.rb
 config.action_mailer.delivery_method = :smtp
 config.action_mailer.smtp_settings = {
   address: 'smtp.163.com',
   port: 25,
   domain: 'mail.163.com',
   user_name: '<username>',
   password: '<password>',
   authentication: :login
 }

多谢 @huopo125

devise.rb

config.mailer_sender = '' 和 # production.rb user_name: '', 是同一个 email 吗?是发邮件的邮箱对吗?

#3 楼 @tracyzhang 不太一样, 如 [email protected],your_email 为 [email protected],username 为 example

谢谢 @huopo125 。回答的十分清楚 :plus1:

@huopo125 亲测,username 是邮箱。[email protected] 是完整的形式。

两种情况我都试过了(username 为 example 还是 [email protected]),都是可以的 @。@ 晕了。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号