[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Simple mail send ... CGI or ActionMailer ?

John N. Alegre

2/21/2006 9:43:00 PM

I want to send some mail using ruby as the CGI.

I have no trouble creating the parsing code.

What I need is a quick easy way to send the mail.

Does the overhead of using ActionMailer under Rails work here. The mail is
a real simple form with text info, no graphics, nothing fancy. Is there
anything in stock Ruby CGI that will send smtp mail? Can someone point me
to some example code?

Thanks
john

7 Answers

Logan Capaldo

2/21/2006 9:49:00 PM

0


On Feb 21, 2006, at 4:43 PM, John N. Alegre wrote:

> I want to send some mail using ruby as the CGI.
>
> I have no trouble creating the parsing code.
>
> What I need is a quick easy way to send the mail.
>
> Does the overhead of using ActionMailer under Rails work here. The
> mail is
> a real simple form with text info, no graphics, nothing fancy. Is
> there
> anything in stock Ruby CGI that will send smtp mail? Can someone
> point me
> to some example code?
>
> Thanks
> john
>
>

You don't have to use the whole Rails stack to make use of ActionMailer.
As far as using something in stock ruby:

http://www.ruby-doc.org/stdlib/libdoc/net/smtp/rdoc/cl...
SMTP.html



james_b

2/21/2006 10:16:00 PM

0

John N. Alegre wrote:
> I want to send some mail using ruby as the CGI.
>
> I have no trouble creating the parsing code.
>
> What I need is a quick easy way to send the mail.
>

I have a script that checks my library for DVDs, and mails my cell phone
when found. Here's the mailing code:


require 'net/smtp'

def sa2( search, url )
send_to_domain = "some-domain.com"
send_to = "mobile@some-domain.com"
send_from_domain = "from-domain.com"
send_from = "james@from-domain.com"

msgstr = "From: Library Checker <#{send_from}>
To: #{send_to} <#{send_to}>
Subject: DVD search notice : #{search} #{Time.new.to_s}
Date: #{Time.new().to_s}
Message-Id: <#{Time.new().to_i}@#{send_from_domain}>

This is a library search alert , sent on #{Time.new().to_s}.\n\n#{msg}"


Net::SMTP.start( "#{send_to_domain}", 25, send_from_domain ) { |smtp|
smtp.send_message( msgstr, send_from, send_to )
}

end
# the end

Sloppy but functional. Beats Blockbuster.

--
James Britt

“Design depends largely on constraints.”
— Charles Eames


David Vallner

2/22/2006 1:01:00 AM

0

Dna Utorok 21 Február 2006 22:43 John N. Alegre napísal:
> I want to send some mail using ruby as the CGI.
>
> I have no trouble creating the parsing code.
>
> What I need is a quick easy way to send the mail.
>
> Does the overhead of using ActionMailer under Rails work here. The mail is
> a real simple form with text info, no graphics, nothing fancy. Is there
> anything in stock Ruby CGI that will send smtp mail? Can someone point me
> to some example code?
>
> Thanks
> john

You can also use the TMail or RubyMail or whichever else mail packages there
out there to make you the mail body of arbitrary fanciness if you don't feel
like making the mail string yourself. Check the RAA.

David Vallner


John N. Alegre

2/22/2006 2:50:00 PM

0

David,

Excuse my ignorance.

What is an RAA?

john

David Vallner wrote:

> You can also use the TMail or RubyMail or whichever else mail packages
> there out there to make you the mail body of arbitrary fanciness if you
> don't feel like making the mail string yourself. Check the RAA.

John N. Alegre

2/22/2006 2:57:00 PM

0

David never mind my question on this. I found it.

James and Logan ... Thanks for your answers.

Just one brief followup question. Can any one who has used them discuss the
advantages of TMail or RubyMail vs simple "rolling your own". Note that in
my case the parsing code to pull the mail out of the form is done. All I
am looking for is an easy way to put that into a email form and send it via
a local SMTP host. Note that the host is not the same machine as the CGI
but is reachable on the LAN.

James's sample code looks like it might work, I have not worked with it yet.
What gains would i get with the TMail or RubyMail packages?

Thanks for the continued help.
john

David Vallner wrote:

> You can also use the TMail or RubyMail or whichever else mail packages
> there out there to make you the mail body of arbitrary fanciness if you
> don't feel like making the mail string yourself. Check the RAA.

John N. Alegre

2/22/2006 3:19:00 PM

0

Again a followup question.

Am I right here ....

RubyMail and TMail would give me methods to parse my text into a mail object
but then I would then still use net/smtp to send that mail object out as
email? Are the mail objects produced by RubyMail or TMail compatible with
sending with net/smtp?

Thanks for the continued attention.
john

John N. Alegre wrote:

> I want to send some mail using ruby as the CGI.
>
> I have no trouble creating the parsing code.
>
> What I need is a quick easy way to send the mail.
>
> Does the overhead of using ActionMailer under Rails work here.  The mail
> is a real simple form with text info, no graphics, nothing fancy.  Is
> there anything in stock Ruby CGI that will send smtp mail?  Can someone
> point me to some example code?
>

David Vallner

2/23/2006 12:52:00 AM

0

Dna Streda 22 Február 2006 16:23 John N. Alegre napísal:
> Again a followup question.
>
> Am I right here ....
>
> RubyMail and TMail would give me methods to parse my text into a mail
> object but then I would then still use net/smtp to send that mail object
> out as email? Are the mail objects produced by RubyMail or TMail
> compatible with sending with net/smtp?
>

You don't need to remember the SMTP format with the headers and stuff, that's
all. It's a slightly less hackish way of going on about things, and as a
bonus, you'll know how to use it if you ever wish to send multipart messages
which are arguably more difficult to encode by hand.

You can do all manners of things with the TMail and RubyMail objects, but you
probably want to call #to_s on those, which gives you the message prepared
for sending with SMTP.

David Vallner