Guest User

Untitled

a guest
Aug 17th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. Why can't the block see my variable?
  2. post "/email/send" do
  3.  
  4. @recipient = params[:email]
  5.  
  6. Mail.deliver do
  7. to @recipient # throws error as this is undefined
  8. from 'server@domain.com'
  9. subject 'testing sendmail'
  10. body 'testing sendmail'
  11. end
  12.  
  13. erb :email_sent
  14.  
  15. end
  16.  
  17. post "/email/send" do
  18.  
  19. Mail.deliver do
  20. to 'me@domain.com'
  21. from 'server@domain.com'
  22. subject 'testing sendmail'
  23. body 'testing sendmail'
  24. end
  25.  
  26. erb :email_sent
  27.  
  28. end
  29.  
  30. recipient = params[:email]
  31. Mail.deliver do
  32. to recipient # 'recipient' is a local variable, not a method, not an instance variable
  33. ...
  34. end
  35.  
  36. Mail.deliver do
  37. to @recipient # throws error as this is undefined
  38. from 'server@domain.com'
  39. subject 'testing sendmail'
  40. body 'testing sendmail'
  41. end
  42.  
  43. Mail.new(
  44. to: @recipient,
  45. from: 'server@domain.com',
  46. subject: 'testing sendmail',
  47. body: 'testing sendmail'
  48. ).deliver!
  49.  
  50. Mail.new(
  51. :to => @recipient,
  52. :from => 'server@domain.com',
  53. :subject => 'testing sendmail',
  54. :body => 'testing sendmail'
  55. ).deliver!
  56.  
  57. pry(main)> Mail.new(
  58. pry(main)* to: 'me@domain.com',
  59. pry(main)* from: 'me@' << `hostname`.strip,
  60. pry(main)* subject: 'test mail gem',
  61. pry(main)* body: 'this is only a test'
  62. pry(main)* ).deliver!
  63. => #<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>>
  64.  
  65. mail = Mail.new
  66. mail.to = 'mikel@test.lindsaar.net'
  67. mail[:from] = 'bob@test.lindsaar.net'
  68. mail['subject'] = 'This is an email'
  69. mail.body = 'This is the body'
Add Comment
Please, Sign In to add comment