您的應用程序/配置/環境/ development.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'example.com',
user_name: '[email protected]',
password: 'YourGmailPassword',
authentication: 'plain',
enable_starttls_auto: true
}
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
config.exceptions_app = self.routes
在user_mailer.rb
class UserMailer < ApplicationMailer
default from: '[email protected]'
def welcome_email(user)
@user = user
@url = 'http://www.example.com'
mail(to: @user.email, subject: 'Welcome to Example.com')
end
end
這工作完全
當我按照[使用Rails發送電子郵件](http://www.tutorialspoint.com/ruby-on-rails/rails-send-email.htm) 中顯示的說明操作時,我遇到錯誤從命令行執行以下操作: ** rails生成郵件程序Usermailer ** Macintosh:mailtest allenroulston $ rails生成郵件程序Usermailer /Users/allenroulston/.rvm/gems/[email protected]/gems/actionmailer -5.0.0/lib目錄/ action_mailer/base.rb:565:在'method_missing的:對的ActionMailer :: Base的 '未定義的方法'DEFAULT_CONTENT_TYPE =': 類你是什麼意思? default_static_extension =(NoMethodError) –
在你的問題中發佈你的錯誤。屏幕截圖 –
提供GitHub的鏈接 –