2017-06-14 50 views
0

我試圖使用SMTP方法,其CONFIGRATION我在development.rb文件來完成,這是使用郵件寶石和SMTP傳遞方法軌發送郵件

Rails.application.configure do 
    config.action_mailer.raise_delivery_errors = true 
    config.action_mailer.delivery_method = :smtp 
     config.action_mailer.smtp_settings = { 
     address:    'smtp.gmail.com', 
     port:     587, 
     domain:    'example.com', 
     user_name:   '[email protected]', 
     password:    xxxxxxxx, 
     authentication:  'plain', 
     enable_starttls_auto: true 
    } 

這裏是UserMailer發送郵件這是郵件程序文件夾下目前,這裏我收到來自控制器和參數的參數值被分配給一個varible,因此,它可以是提供給視圖 UserMailer.rb

class UserMailer < ApplicationMailer 
     default from: '[email protected]' 
     layout 'mailer' 
     def conference_result(email,proposal,acknowledgement,positive,negative,chart) 
      @email = email 
      @proposal = proposal 
      @acknowledgement = acknowledgement 
      @positive = positive 
      @negative = negative 
      @chart = chart 
      mail(to: @email , subject: 'Result for Your conference meeting' , content_type: "text/html") 
     end 
    end 

這裏是我想在郵件中提供的內容, mailer.html.erb

<body> 
     <%= yield %> 
      <h3 class="text-center" id="proposalhead">Proposal</h3> 
      <div style="border:1px solid rgba(0,0,0,0.3);background-color: rgba(255,255,255,0.1);margin-top:10px;margin-bottom:10px;" class="text-center"> 
       <%= @proposal %> 
      </div> 
      <h3 class="text-center hidden" id ="acknowledgementhead">Acknowledgement</h3> 
      <div style="border:1px solid rgba(0,0,0,0.3);background-color: rgba(255,255,255,0.1);margin-top:20px;margin-bottom:20px;" id ="Acknowledgement" class="text-center"> 
       <%= @acknowledgement %> 
      </div> 
      <h3 class="text-center hidden" id ="positivehead">Positive</h3> 
      <div style="border:1px solid rgba(0,0,0,0.3);background-color: rgba(255,255,255,0.1);margin-top:10px;margin-bottom:10px;" id ="Positive" class="text-center"> 
       <%= @positive %> 
      </div> 
      <h3 class="text-center hidden" id ="negativehead">Negative</h3> 
      <div style="border:1px solid rgba(0,0,0,0.3);background-color: rgba(255,255,255,0.1);margin-top:10px;margin-bottom:20px" id = "Negative" class="text-center"> 
       <%= @negative %> 
      </div> 
      <div id="chart_div" style="width:100%;margin-bottom: 15px;margin-top:15px;" class="text-center"> 
       <%= @chart %> 
      </div>  
     </body> 

當我嘗試發送郵件,它顯示以下錯誤

ActionView :: MissingTemplate(缺少具有「郵件程序」的模板user_mailer/conference_result。搜查:* 「user_mailer文件」)

請幫我,我是新來的紅寶石。

+0

「user_mailer」forlder中是否有conference_result電子郵件模板? –

回答

3

如錯誤所述,缺少模板user_mailer/conference_result

你需要創建一個模板app/views/user_mailer/conference_result.html.erb

+0

感謝您的幫助,gmail正在發送郵件,但發送了郵件,Google只是阻止某人登錄您的Google帳戶。如何克服這一點。 –

+0

在這裏登錄您的帳戶並啓用訪問不太安全的應用程序https://www.google.com/settings/security/lesssecureapps –

+0

謝謝,我已經完成了它。我發送的內容不是顯示在一個適當的格式。我收到這樣的郵件--- == _ mimepart_5940e1d369d8f_282d2658644331d6 Content-Type:text/plain; charset = UTF-8 Content-Transfer-Encoding:7bit ---- == _ mimepart_5940e1d369d8f_282d2658644331d6 Content-Type:text/html; charset = UTF-8 Content-Transfer-Encoding:引用可打印 –

0

看來你錯過了郵件模板本身。如果你沒有得到它,那就解釋了錯誤 - 否則我會確保它在正確的文件夾中,可能是app/views/user_mailer/conference_result.html.erb.text.erb

+0

謝謝您的幫助.Gmail正在發送郵件,但郵件中包含Google,但Google只是阻止某人登錄您的Google帳戶。如何解決此問題 –

0
https://myaccount.google.com/u/0/lesssecureapps 

登錄您的電子郵件,然後上面的鏈接打開。 啓用較不安全的應用程序。