Rails: How to use ActionMailer by itself?
actionmailer, ruby, ruby-on-rails
Solution
The underlying functionality for ActionMailer is provided by the mail gem. This allows you to send mail very simply, e.g:
Mail.deliver do
from 'me@test.lindsaar.net'
to 'you@test.lindsaar.net'
subject 'Here is the image you wanted'
body File.read('body.txt')
add_file :filename => 'somefile.png', :content => File.read('/somefile.png')
end
It supports delivery by all the same methods that ActionMailer does.
Problem
I am creating an app that will be used to send emails. I don't need to use regular mailers and view templates because I will simply be receiving the data that will be used to generate the email. However, I assume that there are some benefits to using `ActionMailer` instead of interacting with `SMTP` directly. I ran into issues while trying to instantiate a new instance of `ActionMailer::Base`. How can I use `ActionMailer` by itself without having to define a new class that extends `ActionMailer::Base`?