Net/smtp

I am not sure if I've properly understood things correctly but....

I am trying to emulate sample code in the RDOC's of ruby core.
can some one assist?

Error is...
./barcode_class_rpt_email.rb:199:in `send_email': wrong number of
arguments (5 for 4) (ArgumentError)

code that generate this is this...

require 'sendemail'

def init
  @email = Sendemail.new

lots of code between and in a fxruby class (don't know if this is an
issue).

198 uname.each do |receipiant|
199 @email.send_email(@sender,receipiant, 'Automatic Patrol
Report', @msg, @server)
          end

the called script (it is referenced correctly).

# sendemail.rb
require 'net/smtp'

class Sendemail
  def send_email(from, to, subject, message, server)

      Net::SMTP.start("#{server}", 25) do |smtp|
        smtp.set_debug_output $stdout

        smtp.open_message_stream("#{from}", "#{to}") do |f|
          f.puts "From: #{from}"
          f.puts "To: #{to}"
          f.puts "Subject: #{subject}"
          f.puts
          f.puts "#{message}"
        end
      end
  end
end

=begin
#test code for the class commented out when trying to use within project
a = Sendemail.new

a.send_email "isp.email.address", "online@yahoo.com", "test", "a
message", "smtp.isp.mail.server"

=end

I have changed the calling code (shown again below)
@email.send_email(@sender,receipiant, 'Automatic Patrol Report', @msg,
@server)

to code below thinking the code below will fix things to no avail.
@email.send_email("#{@sender}","#{receipiant}", "Automatic Patrol
Report", "#{@msg}", "#{@server}")

Why? I am sending across 5 parameters, see the test case above it works!
it I for go 1 parameter then it works, but which one do I loose and why
that one?

I want the class to be as dynamic as possible so I can "just" call it
into another project I want to send emails out from.

any help appreciated.

dave

···

--
Posted via http://www.ruby-forum.com/.

When I send mail using Ruby, I use Pony.

http://adam.heroku.com/past/2008/11/2/pony_the_express_way_to_send_email_from_ruby/

require

'rubygems'
require 'pony'
Pony.mail(:to => 'you@example.com', :from => 'me@example.com', :subject => 'Hello')

Also permits to connect to an smtp server.

thanks MRZombie,

Will look into this.

still have you any ideas why I have my current problem thou?

MrZombie wrote:

···

When I send mail using Ruby, I use Pony.

http://adam.heroku.com/past/2008/11/2/pony_the_express_way_to_send_email_from_ruby/

require

'rubygems'
require 'pony'
Pony.mail(:to => 'you@example.com', :from => 'me@example.com', :subject
=> 'Hello')

Also permits to connect to an smtp server.

--
Posted via http://www.ruby-forum.com/\.

update to the issue.

Have tried code sample posted at this url
http://newsgroups.derkeiler.com/Archive/Comp/comp.lang.ruby/2009-06/msg02082.html

and still get my error!!!

now can anyone explain to me why this issue is happening?

I have my fox class app.

my email class being required into it.
a module being required into it also.

in the init of my fox class i have....

@email = @Emails.new

but when ever I edit the script it seems not to reflect in my execution
(eg i've commented out *ALL* references to require net/smtp, Net::SMTP
code but i still get an error relating to 5 parameters passed when only
4 are required.

this is strange (unless is the GC not clearing out the last run of my
program).

···

--
Posted via http://www.ruby-forum.com/.