Simple mail send ... CGI or ActionMailer ?

J

John N. Alegre

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
 
L

Logan Capaldo

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/classes/Net/
SMTP.html
 
J

James Britt

John said:
I want to send some mail using ruby as the CGI.
=20
I have no trouble creating the parsing code.
=20
What I need is a quick easy way to send the mail.
=20

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


require 'net/smtp'

def sa2( search, url )
send_to_domain =3D "some-domain.com"
send_to =3D "(e-mail address removed)"
send_from_domain =3D "from-domain.com"
send_from =3D "(e-mail address removed)"

msgstr =3D "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.

--=20
James Britt

=93Design depends largely on constraints.=94
=97 Charles Eames
 
D

David Vallner

D=C5=88a Utorok 21 Febru=C3=A1r 2006 22:43 John N. Alegre nap=C3=ADsal:
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 ther=
e=20
out there to make you the mail body of arbitrary fanciness if you don't fee=
l=20
like making the mail string yourself. Check the RAA.

David Vallner
 
J

John N. Alegre

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
 
J

John N. Alegre

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
 
D

David Vallner

D=C5=88a Streda 22 Febru=C3=A1r 2006 16:23 John N. Alegre nap=C3=ADsal:
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=20
all. It's a slightly less hackish way of going on about things, and as a=20
bonus, you'll know how to use it if you ever wish to send multipart message=
s=20
which are arguably more difficult to encode by hand.

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

David Vallner
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top