[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Need Help Using Net::SMTP

Dan Diebolt

12/29/2005 9:59:00 AM

I am trying to send email from my comcast email account (say me@comcast.net) to my yahoo email accout (say me@yahoo.com) from a ruby script using net/smtp:

require 'net/smtp'
Net::SMTP.start("smtp.comcast.net", 25,"localhost","user","pass") do |smtp|
smtp.send_message "hello","me@comcast.net","me@yahoo.com"
end

After trying the above ruby in irb I get the following message with no email delivered:

=> "250 Mail queued for delivery.\n"

I don't understand how the third argument to Net::SMTP.start should be specified; its called "helo" and documentation says it defaults to 'localhost.localdomain'. I would appreciate it if anyone could point out what I am doing wrong.

I am pretty sure I have the smtp, pop3 and ports identified correctly as I can send email using the command line utility postie (http://www.infradig.com/postie/i...):

postie -esmtp -host:smtp.comcast.net -to:me@yahoo.com -from:me@comcast.net -s:subject -msg:hello -user:user -pass:pass

#Incoming mail (POP3): mail.comcast.net
#Incoming mail (POP3): 110
#Outgoing mail (SMTP): smtp.comcast.net
#Outgoing mail (SMTP): port is set to 25




---------------------------------
Yahoo! Shopping
Find Great Deals on Holiday Gifts at Yahoo! Shopping
6 Answers

tsumeruby

12/29/2005 11:01:00 AM

0

On Thursday 29 December 2005 06:59 pm, Dan Diebolt wrote:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...
The "250 Mail queued for delivery.\n" message is from the mail server. You
may be getting caught by a spam filter. The email is supposed to be received.

Tsume

> I am trying to send email from my comcast email account (say
> me@comcast.net) to my yahoo email accout (say me@yahoo.com) from a ruby
> script using net/smtp:
>
> require 'net/smtp'
> Net::SMTP.start("smtp.comcast.net", 25,"localhost","user","pass") do |smtp|
> smtp.send_message "hello","me@comcast.net","me@yahoo.com"
> end
>
> After trying the above ruby in irb I get the following message with no
> email delivered:
>
> => "250 Mail queued for delivery.\n"
>
> I don't understand how the third argument to Net::SMTP.start should be
> specified; its called "helo" and documentation says it defaults to
> 'localhost.localdomain'. I would appreciate it if anyone could point out
> what I am doing wrong.
>
> I am pretty sure I have the smtp, pop3 and ports identified correctly as
> I can send email using the command line utility postie
> (http://www.infradig.com/postie/i...):
>
> postie -esmtp -host:smtp.comcast.net -to:me@yahoo.com
> -from:me@comcast.net -s:subject -msg:hello -user:user -pass:pass
>
> #Incoming mail (POP3): mail.comcast.net
> #Incoming mail (POP3): 110
> #Outgoing mail (SMTP): smtp.comcast.net
> #Outgoing mail (SMTP): port is set to 25


Dan Diebolt

12/29/2005 11:19:00 AM

0

>You may be getting caught by a spam filter.

I can post email using postie so I can't see a problem with the basic credentials being sent. There must be some configuration of Net::SMTP that will allow me to email from Ruby. Anyone have a clue what to do?


---------------------------------
Yahoo! Photos
Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.

Kero van Gelder

12/29/2005 12:05:00 PM

0

On 2005-12-29, Dan Diebolt <dandiebolt@yahoo.com> wrote:
> --0-1020623145-1135855120=:46005
> Content-Type: text/plain; charset=iso-8859-1
> Content-Transfer-Encoding: quoted-printable
>
>>You may be getting caught by a spam filter.
>
> I can post email using postie so I can't see a problem with the basic c
> redentials being sent. There must be some configuration of Net::SMTP that
> will allow me to email from Ruby. Anyone have a clue what to do?

$ ri send_message
------------------------------------------------- Net::SMTP#send_message
send_message( msgstr, from_addr, *to_addrs )
------------------------------------------------------------------------
Sends msgstr as a message. Single CR ("\r") and LF ("\n") found in
the msgstr, are converted into the CR LF pair. You cannot send a
binary message with this method. msgstr should include both the
message headers and body.

"...both the message headers and the body" does not seem to be covered by a
string like "hello", in other words you are complying to SMTP but not to RFC
822. Lacking a From/Reply-To address you do not receive the Delivery Failure
message, I suppose. An (incomplete!) snippet from what I use:

header = [
"To: #{to.join(', ')}",
"Subject: #{subject}",
"Date: #{Time.now.rfc822}",
"From: Arena II <#{ArenaMail}>"
]
Net::SMTP.start("localhost", 25, SiteDNS) { |smtp|
smtp.sendmail(header.join("\n")+"\n\n"+msg, ArenaMail, rcpts)
}

(in which I should use \r\n but as the docs say, it does not matter)

Hth,
Kero.

PS: there are higher level mail libraries for Ruby, iirc.

Ross Bamford

12/29/2005 12:16:00 PM

0

On Thu, 29 Dec 2005 11:18:52 -0000, Dan Diebolt <dandiebolt@yahoo.com>
wrote:

>> You may be getting caught by a spam filter.
> I can post email using postie so I can't see a problem with the basic
> credentials being sent. There must be some configuration of Net::SMTP
> that will allow me to email from Ruby. Anyone have a clue what to do?
>

Seriously, 250 is the SMTP +OK code so your mail is good to go. My guess
is it's getting rejected somewhere down the line.

A couple of things you might check:

SMTP HELO is often used to determine authorization
to relay mail, and it should be the domain you're
sending mail from. So from your example I guess you
want comcast.net.

Most SMTP accounts don't require username/password,
and if they do you'll need to specify an auth type
too. Check out your account settings in your mailer
to see what you want to use. It's the last arg to
Net::SMTP.start.

Hope that helps,

--
Ross Bamford - rosco@roscopeco.remove.co.uk

Ross Bamford

12/29/2005 12:19:00 PM

0

On Thu, 29 Dec 2005 12:15:41 -0000, Ross Bamford
<rosco@roscopeco.remove.co.uk> wrote:

> A couple of things you might check:
>

No sender/subject is also a trigger for many spam filters I believe...

--
Ross Bamford - rosco@roscopeco.remove.co.uk

mathew

1/3/2006 7:58:00 PM

0

Dan Diebolt wrote:
> I am trying to send email from my comcast email account (say me@comcast.net) to my yahoo email accout (say me@yahoo.com) from a ruby script using net/smtp:
>
> require 'net/smtp'
> Net::SMTP.start("smtp.comcast.net", 25,"localhost","user","pass") do |smtp|
> smtp.send_message "hello","me@comcast.net","me@yahoo.com"
> end
>
> After trying the above ruby in irb I get the following message with no email delivered:
>
> => "250 Mail queued for delivery.\n"
>
> I don't understand how the third argument to Net::SMTP.start should be specified; its called "helo" and documentation says it defaults to 'localhost.localdomain'. I would appreciate it if anyone could point out what I am doing wrong.

You should probably read the SMTP protocol spec in the SMTP RFC linked
to at the top of the documentation for Net::SMTP (RFC2821). Maybe your
copy is out of date, in which case try <URL:http://www.ruby-doc.org/s...

You should also note the bit that says:

This library does NOT provide functions to compose internet mails. You
must create them by yourself. If you want better mail support, try
RubyMail or TMail. You can get both libraries from RAA.
(www.ruby-lang.org/en/raa.html)

The thing you are attempting to send (the word "hello") is not an
Internet format e-mail. Look at the example for Net::SMTP, or read
RFC2822, also linked to from the documentation for Net::SMTP.

The HELO parameter is the fully-qualified DNS name of your system. The
server you are connecting to may or may not choose to check that (a) it
resolves to a real IP address, and (b) it resolves to the same IP
address you're connecting from. Again, the documentation mentions this.


mathew
--
<URL:http://www.pobox.com/...
My parents went to the lost kingdom of Hyrule
and all I got was this lousy triforce.