Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Why can't the block see my variable?
- post "/email/send" do
- @recipient = params[:email]
- Mail.deliver do
- to @recipient # throws error as this is undefined
- from 'server@domain.com'
- subject 'testing sendmail'
- body 'testing sendmail'
- end
- erb :email_sent
- end
- post "/email/send" do
- Mail.deliver do
- to 'me@domain.com'
- from 'server@domain.com'
- subject 'testing sendmail'
- body 'testing sendmail'
- end
- erb :email_sent
- end
- recipient = params[:email]
- Mail.deliver do
- to recipient # 'recipient' is a local variable, not a method, not an instance variable
- ...
- end
- Mail.deliver do
- to @recipient # throws error as this is undefined
- from 'server@domain.com'
- subject 'testing sendmail'
- body 'testing sendmail'
- end
- Mail.new(
- to: @recipient,
- from: 'server@domain.com',
- subject: 'testing sendmail',
- body: 'testing sendmail'
- ).deliver!
- Mail.new(
- :to => @recipient,
- :from => 'server@domain.com',
- :subject => 'testing sendmail',
- :body => 'testing sendmail'
- ).deliver!
- pry(main)> Mail.new(
- pry(main)* to: 'me@domain.com',
- pry(main)* from: 'me@' << `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: me@myhost.domain.com>, <To: me@domain.com>, <Message-ID: <4eaad1cab65ce_579b2e8e6c42976d@myhost.domain.com>>, <Subject: test mail gem>, <Mime-Version: 1.0>, <Content-Type: text/plain>, <Content-Transfer-Encoding: 7bit>>
- mail = Mail.new
- mail.to = 'mikel@test.lindsaar.net'
- mail[:from] = 'bob@test.lindsaar.net'
- mail['subject'] = 'This is an email'
- mail.body = 'This is the body'
Add Comment
Please, Sign In to add comment