# Net/smtp

**URL:** <https://www.ruby-forum.com/t/net-smtp/192329>\
**Category:** Ruby\
**Created:** [July 28, 2010, 11:46am UTC](https://www.ruby-forum.com/t/net-smtp/192329 "2010-07-28T11:46:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [July 28, 2010, 11:46am UTC](https://www.ruby-forum.com/t/net-smtp/192329/1 "2010-07-28T11:46:36Z")

</div>

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”, “removed\_email\_address@domain.invalid”, “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

---

<div class="post-metadata">

**Author:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [July 28, 2010, 12:30pm UTC](https://www.ruby-forum.com/t/net-smtp/192329/2 "2010-07-28T12:30:35Z")

</div>

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/](http://adam.heroku.com/past/2008/11/2/pony_the_express_way_to_send_email_from_ruby/)

require

‘rubygems’  
require ‘pony’  
Pony.mail(:to =\> ‘removed\_email\_address@domain.invalid’, :from =\> ‘removed\_email\_address@domain.invalid’, :subject  
=\> ‘Hello’)

Also permits to connect to an smtp server.

---

<div class="post-metadata">

**Author:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [July 29, 2010, 8:55am UTC](https://www.ruby-forum.com/t/net-smtp/192329/3 "2010-07-29T08:55:47Z")

</div>

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/](http://adam.heroku.com/past/2008/11/2/pony_the_express_way_to_send_email_from_ruby/)
> 
> require
> 
> ‘rubygems’  
> require ‘pony’  
> Pony.mail(:to =\> ‘removed\_email\_address@domain.invalid’, :from =\> ‘removed\_email\_address@domain.invalid’, :subject  
> =\> ‘Hello’)
> 
> Also permits to connect to an smtp server.

---

<div class="post-metadata">

**Author:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [July 29, 2010, 10:59am UTC](https://www.ruby-forum.com/t/net-smtp/192329/4 "2010-07-29T10:59:15Z")

</div>

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](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).
