Setting the delivery_method immediately within the delivery block instead of setting the defaults to send seems to work well with the following code:
Mail.deliver do
delivery_method :smtp,
address: "smtp.gmail.com",
domain: "#####",
port: 587,
user_name: from,
password: "#####",
enable_starttls_auto: true
from from
to to
subject subject
body "default body"
end
But how do I do the same to read?
Mail.last do
retriever_method :imap,
user_name: to,
password: password,
address: server,
port: port,
enable_ssl: true
end
causes
*** NoMethodError Exception: undefined method `retriever_method' for #<RSpec::ExampleGroups::Nested::Nested_2::Nested::Email_2:0x00007fa246110478>
FYI: this gem is OSS.
Mail#delivery_methodis technically an alias toConfiguration.instance.delivery_method.Mail#retriever_methodin turn redirects toConfiguration.instance.retriever_method.Unlike
Mail::deliver, that creates a new instance,Mail::lastexplicitly callsretriever_method.last(*args, &block).As one might see, instance allows to override
delivery_method, but notretriever_method.So you should store
Configuration.instance.retriever_methodinto intermediate variable, update it, callMail::lastand restore it back. Somewhat along these lines: