Hello,
I need a module for sending emails.
Could you show me where I can find it and what’s the syntax?
Thanks.
Hello,
I need a module for sending emails.
Could you show me where I can find it and what’s the syntax?
Thanks.
Ruby N. wrote:
Hello,
I need a module for sending emails.
Could you show me where I can find it and what’s the syntax?
Thanks.
Have fun!
require ‘net/smtp’
Net::SMTP.start(‘smtp.example.com’, 25) do |smtp|
smtp.open_message_stream(‘from_addr’, [to_addr]) do |f|
f.puts ‘From: [email protected]’
f.puts ‘To: [email protected]’
f.puts ‘Subject: test message’
f.puts ‘This is a test message.’
end
end
Derek
On Thu, Dec 31, 2009 at 9:43 PM, Derek S.
[email protected] wrote:
require ‘net/smtp’
Net::SMTP.start(‘smtp.example.com’, 25) do |smtp|
smtp.open_message_stream(‘from_addr’, [to_addr]) do |f|
f.puts ‘From: [email protected]’
f.puts ‘To: [email protected]’
f.puts ‘Subject: test message’
f.puts ‘This is a test message.’
end
endDerek
Take a look at tmail also.
It goes without saying that you should follow the law. In the United
States ( I don’t know about other countries’ laws)
We have the CAN SPAM act.
Make sure you follow it, because people who spam should be
#{insert_your_patent_of_punishment}
Andrew McElroy
On Thu, Dec 31, 2009 at 11:12 PM, Ayumu A. [email protected]
wrote:
Hi
You can also use ActionMailer.
ActionMailer uses tmail
see below:
http://am.rubyonrails.org/
Andrew McElroy
Hi
You can also use ActionMailer.
Ayumu AIZAWA
twitter.com/ayumin
Hello,
I need a module for sending emails.
Could you show me where I can find it and what’s the syntax?
Thanks.
To add to your confusion on what to use, I’d suggest you use the Mail
gem, which is TMail’s successor: GitHub - mikel/mail: A Really Ruby Mail Library
I’m betting it will become part of the Ruby standard library, but who
knows. I think it should anyways.
On 01.01.2010 07:06, Ruby N. wrote:
Thanks, that works.
But from syntax point to see, what’s Net::SMTP.start(‘smtp.example.com’, 25)?
why it can accept a block as argument?
Because it the #start method was written that way.
The reason, I imagine, is to provide some failure resistance: If a code
gets exited, the environment gets “reset” (DB connections get closed,
files written to disk, etc).
what’s the content of “smtp”?
Take a look at it with smtp.inspect in the block.
why “smtp” (it seems being taken from God) has the method of
“open_message_stream”?
smtp is a block variable (the | at each side tells Ruby that).
Since smtp is a block variable in a Net::SMTP block, it gains access to
the methods Net::SMTP provides to its blocks.
You could’ve named the block variable |s| or |richard|, and the methods
would still work.
It makes life easier if the variable’s name tells you what it does when
you read the name.
and what other methods it does also have?
smtp.methods
Sorry for my newbie questions.
A handy tip I use when I explore something new:
You can #inspect objects or check its #methods in Ruby, and #sort the
output. A simple “puts Class.methods” shows you, in the terminal / on
the command line which methods the class Class has. “puts
Class.methods.sort” sorts the output for you (alphabetically in this
case).
On Fri, Jan 1, 2010 at 2:16 PM, Phillip G. [email protected]
wrote:
Could you show me where I can find it and what’s the syntax?
   f.puts ‘Subject: test message’Because it the #start method was written that way.
The reason, I imagine, is to provide some failure resistance: If a code gets
exited, the environment gets “reset” (DB connections get closed, files
written to disk, etc).
Thanks Phillip.
Can you kindly tell me how to write that a method?
I know something like:
class Myclass
def myfunc a,b,c
do_something_with a,b,c
end
end
x= Myclass.new
x.myfunc(1,2,3)
but I dont know how to write a method which accepts a block (like the
above smtp one).
THanks.
Jenn.
On Fri, Jan 1, 2010 at 11:43 AM, Derek S.
[email protected] wrote:
require ‘net/smtp’
 Net::SMTP.start(‘smtp.example.com’, 25) do |smtp|
  smtp.open_message_stream(‘from_addr’, [to_addr]) do |f|
   f.puts ‘From: [email protected]’
   f.puts ‘To: [email protected]’
   f.puts ‘Subject: test message’
   f.puts ‘This is a test message.’
  end
 end
Thanks, that works.
But from syntax point to see, what’s Net::SMTP.start(‘smtp.example.com’,
25)?
why it can accept a block as argument?
what’s the content of “smtp”?
why “smtp” (it seems being taken from God) has the method of
“open_message_stream”?
and what other methods it does also have?
Sorry for my newbie questions.
Regards,
Jenn.
On 01.01.2010 07:26, Ruby N. wrote:
Thanks Phillip.
Can you kindly tell me how to write that a method?
Not me directly, no, but I found this:
http://blog.codahale.com/2005/11/24/a-ruby-howto-writing-a-method-that-uses-code-blocks/
but I dont know how to write a method which accepts a block (like the
above smtp one).
THanks.
It’s not much different than that.
def block
yield
end
is a simple block method already. Not terribly useful, but it’s the
foundation to build from.
On Fri, Jan 1, 2010 at 2:33 PM, Phillip G. [email protected]
wrote:
On 01.01.2010 07:26, Ruby N. wrote:
Thanks Phillip.
Can you kindly tell me how to write that a method?Not me directly, no, but I found this:
http://blog.codahale.com/2005/11/24/a-ruby-howto-writing-a-method-that-uses-code-blocks/
Thanks.
I really like that!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs