【发布时间】:2015-09-27 06:51:46
【问题描述】:
我正在尝试从 lib 目录中的文件发送邮件。我使用Action Mailer Basics 来帮助我配置它。我可以从我的控制器成功发送邮件,所以我认为我的问题是我的 lib 文件“filename.rb”中没有正确要求邮件程序。
我运行ruby filename.rb 并得到
/pathtofile/lib/otherfile.rb:37:in `alert': uninitialized constant UserMailer (NameError)
from filename.rb:47:in `block in <main>'
from filename.rb:35:in `secondly_loop'
from filename.rb:47:in `<main>'
文件名.rb
alert
otherfile.rb
def alert
#send email http://www.gotealeaf.com/blog/handling-emails-in-rails
UserMailer.mailer_method().deliver_now
puts "Sent Email"
end #end def alert
app/mailers/user_mailer.rb
class UserMailer < ApplicationMailer
default from: 'email@email.com'
def mailer_method(a)
@a = a
mail(to: 'email@email.com', subject: "Hello you have new mail")
end
end
app/views/mailer_method.html.erb
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h2>Daniel, </h2>
<p>Your email is boring and has arrived now.<br><br>
Sincerely,<br>
Daniel</p>
</body>
</html>
【问题讨论】:
标签: ruby-on-rails ruby actionmailer