Mail
のドキュメントをもう一度読むと、うまくいく別の解決策が見つかるはずです。むしろ使用より:
Mail.deliver do
to @recipient # throws error as this is undefined
from '[email protected]'
subject 'testing sendmail'
body 'testing sendmail'
end
あなたはパラメータを渡し、メールのnew()
メソッドを使用して、ブロックを無視することができます。
Mail.new(
to: @recipient,
from: '[email protected]',
subject: 'testing sendmail',
body: 'testing sendmail'
).deliver!
または代替ハッシュ要素の定義:てこで
Mail.new(
:to => @recipient,
:from => '[email protected]',
:subject => 'testing sendmail',
:body => 'testing sendmail'
).deliver!
を、またはあなたが見るでしょう:
pry(main)> Mail.new(
pry(main)* to: '[email protected]',
pry(main)* from: '[email protected]' << `hostname`.strip,
pry(main)* subject: 'test mail gem',
pry(main)* body: 'this is only a test'
pry(main)*).deliver!
=> #<Mail::Message:59273220, Multipart: false, Headers: <Date: Fri, 28 Oct 2011 09:01:14 -0700>, <From: [email protected]>, <To: [email protected]>, <Message-ID: <[email protected]>>, <Subject: test mail gem>, <Mime-Version: 1.0>, <Content-Type: text/plain>, <Content-Transfer-Encoding: 7bit>>
new
メソッドには、いくつかのバリエーションがあります。
さらに、Mail :: Messageオブジェクトを直接作成し、文字列、記号、またはダイレクトで値を渡して新しいメールを作成することもできますメソッド呼び出し。詳細については、Mail :: Messageを参照してください。mail.deliver!
続い
mail = Mail.new
mail.to = '[email protected]'
mail[:from] = '[email protected]'
mail['subject'] = 'This is an email'
mail.body = 'This is the body'
。
また、前の例では、メッセージエンベロープのさまざまなヘッダーにアクセスする複数の方法があることにも注意してください。それはよく考えられているように見え、Rubyのやり方にしっかりと従っている柔軟な宝石です。
あなたの問題は 'params [:email]'ではなく、インスタンスのvarであると確信していますか?あなたはそれを出力しようとしましたか?とにかくブロックがクロージャなので、ローカル変数もここで十分でなければなりません。 –