<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # 10.3 在生產環境中發送郵件 我們已經成功實現了賬戶激活和密碼重設功能,本節要配置應用,讓它在生產環境中能真正地發送郵件。我們首先搭建一個免費的郵件服務,然后配置應用,最后再部署。 我們要在生產環境中使用 SendGrid 服務發送郵件。這個服務是 Heroku 的擴展,只有通過認證的賬戶才能使用。(要在 Heroku 的賬戶中填寫信用卡信息,不過認證不收費。)對我們的應用來說,入門套餐(免費,寫作本書時限制每天最多只能發送 400 封郵件)就夠了。我們可以使用下面的命令添加這個擴展: ``` $ heroku addons:create sendgrid:starter ``` 為了讓應用使用 SendGrid 發送郵件,我們要配置生產環境的 [SMTP](https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol) 設置,而且還要定義一個 `host` 變量,設置生產環境中網站的地址,如[代碼清單 10.56](#listing-sendgrid-config) 所示。 ##### 代碼清單 10.56:配置應用在生產環境中使用 SendGrid config/environments/production.rb ``` Rails.application.configure do . . . config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :smtp host = '<your heroku app>.herokuapp.com' config.action_mailer.default_url_options = { host: host } ActionMailer::Base.smtp_settings = { :address => 'smtp.sendgrid.net', :port => '587', :authentication => :plain, :user_name => ENV['SENDGRID_USERNAME'], :password => ENV['SENDGRID_PASSWORD'], :domain => 'heroku.com', :enable_starttls_auto => true } . . . end ``` [代碼清單 10.56](#listing-sendgrid-config) 中設置了 SendGrid 賬戶的用戶名(`user_name`)和密碼(`password`),但是注意,這兩個值是從 `ENV` 環境變量中獲取的,而沒有直接寫入代碼。這是生產環境應用的最佳實踐,為了安全,絕不能在源碼中寫入敏感信息,例如原始密碼。這兩個值由 SendGrid 擴展自動設置,[11.4.4 節](chapter11.html#image-upload-in-production)會介紹如何自己定義。如果好奇,可以使用下面的命令查看這兩個環境變量的值: ``` $ heroku config:get SENDGRID_USERNAME $ heroku config:get SENDGRID_PASSWORD ``` 現在,應該把主題分支合并到主分支中: ``` $ bundle exec rake test $ git add -A $ git commit -m "Add password resets & email configuration" $ git checkout master $ git merge account-activation-password-reset ``` 然后,推送到遠程倉庫,再部署到 Heroku: ``` $ bundle exec rake test $ git push $ git push heroku master $ heroku run rake db:migrate ``` 配置好 SendGrid 服務后,在生產環境的演示應用中使用你的電子郵件注冊試試。你應該會收到一封激活郵件,如[圖 10.20](#fig-activation-email-production) 所示。如果忘記密碼(或者假裝忘了),可以使用 [10.2 節](#password-reset)實現的功能重設密碼,收到的重設郵件如[圖 10.21](#fig-reset-email-production) 所示。 ![activation email production](https://box.kancloud.cn/2016-05-11_5733306c5d6a5.png)圖 10.20:生產環境中的應用發送的賬戶激活郵件![reset email production](https://box.kancloud.cn/2016-05-11_5733306c840e0.png)圖 10.21:生產環境中的應用發送的密碼重設郵件
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看