If you have a SMTP server avaliable you can use the script below:

require 'net/smtp'

class SendMail < Net::SMTP

 

     def initialize(options)

         super

         @user     = options["user"]  

         @from     = options["from"] 

         @to       = options["to"].to_a 

         @pass     = options["pass"]  

         @server   = options["server"]

         @subject  = options["subject"]

     end

     def body=(mail_body)

        

         # BUILD HEADERS

         

         @body =  "From: #{@from} <#{@from}>\n" 

         @body << "To: #{@to}<#{@to}>\n"

         @body << "Subject: #{@subject}\n"

         @body << "Date: #{Time.now}\n"

         @body << "Importance:high\n"

         @body << "MIME-Version:1.0\n"

         @body << "\n\n\n"

         

         # MESSAGE BODY

         

         @body << mail_body

     end

     def send

       @to.each do | to |

          Net::SMTP.start(@server, 25 , @from , @user , @pass , :login)  do |smtp|

            smtp.send_message(@body,@from,to)

          end

       end

        

     end

         

end

if __FILE__ == $0

    print  %^USAGE:

    o=Hash.new    

    o["user"]    = "userid"

    o["from"]    = "rodrigo.bermejo / ae.ge.com"

    o["pass"]    = "neverguess"

    o["server"]  = "smtp server"

    o["subject"] = "TEST MESSAGE"

    mail=SendMail.new(o)

    mail.body="Hi buddy"

    mail.send

    ^

end



Bauduin Raphael wrote:

> Hi,
>
> I have to send a mail from a Ruby script, and wonder what's the best way
> to do it.
>
> I saw net/smpt, but I need to write the headers myself (eg if I want to
> define a subject I have to write Subject: blah\n )
> I saw Rubymail, which anable me to easily construct a mail with headers,
> but it doesnt send it (same for Tmail I think).
>
> So, do I have to combine both to send a mail? Isn't there simply
> something like
>
> Mail::send_mail(from, to, subject, body) ?
>
> Thanks for your help and advices.
>
> Raph