I am trying to send mail from a file in lib directory. I used Action Mailer Basics to help me configure this. I can successfully send mail from my controller so I think my problem is not properly requiring the mailer in my lib file "filename.rb".
I run ruby filename.rb
and get
/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>'
filename.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>