What you see is because the block
inside Mail.new
is in a different scope than @final_file
, as the code calls:
if block_given?
instance_eval(&block)
end
This means that the block is run from within Mail
's scope. This enables you to call methods like from
and to
.
As far as I understand from the code, you can pass arguments to the initializer like this:
mail = Mail.new(final_path: @final_file.path) do
from 'me@somehost.net'
to 'mymail@mydomain.com'
subject 'Some subject'
body "here the body"
add_file :filename => 'filename.html', :content => File.read(self[:final_path])
end
(this is untested, so the syntax needed might be a little different).