class UserMailer < ActionMailer::Base default from: "@126.com"
def send_mail(params = {})
@url = 'http://example.com/login'
mail( :subject => 'abcAAAAAAAASDFADSFADSFADSFDASFASDF',
:to => "@qq.com",
:from => '@126.com',
:date => Time.now
)
end
end
定义了一个方法,然后在我的一个控制器里面,UserMailer.send_mail(nil).deliver 发邮件。
environment.rb 里面的配置如下:
config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: 'smtp.126.com', port: 25, domain: '126.com', user_name: '[email protected]', password: 'xxxxx', authentication: 'login', enable_starttls_auto: true }
但是最后,会报错: Missing template user_mailer/send_mail with "mailer". Searched in: * "user_mailer"