Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Can't get net/smtp to send outside of LAN?

Reply
Thread Tools

Can't get net/smtp to send outside of LAN?

 
 
John N. Alegre
Guest
Posts: n/a
 
      03-09-2006
I am trying to use net/smtp to send a mail message. What I am finding is
that I can send a email message on the LAN but it never gets out to the
world. What am I missing?

Here is my test code:
################################################## ##################
require('net/smtp')

class Email
def Email.send(date, body, server = 'localhost', port = 25)
Net::SMTP.start(server, port) { |mailer|
text =
"From: info\n" <<
"To: usr@domain\n" <<
"Date: #{date}\n" <<
"Subject: New entry in Database\n" <<
"Importance: High\n" <<
"MIME-Version: 1.0\n" <<
"Sender: #{self.class.name}\n" <<
"\n\n\n" <<
body

mailer.send_message(text, "info", "usr@domain")
}
end

end

Email.send("#{Time.now}", "New entry in database at #{ Time.now}\n")
puts "end of code"
################################################## ##################
on the LAN SMTP server with 'localhost' and usr@domain being a user on the
same machine WORKS OK ... with 'localhost' replaced with 'machine' where
machine is the machine on the LAN that sends SMTP mail and usr@domain is a
user on that same machine and the code is run anywhere on the LAN it WORKS
OK to a user on 'machine' ...

HOWEVER ...

if usr@domain is outside the LAN the mail never gets sent either if the code
is run on 'localhost' or on a machine on the LAN with 'machine' replaced by
the IP of the SMTP server. I know 'machine' will serve as a SMTP host for
mailers such as evolution or Mac OX X mailer because I use it for that all
the time.

What am I missing.

I know I could go to a better Ruby package such as TMail or RubyMail or
bring out the cannons and use ActionMailer but if I don't understand what
is happening at this basic level that might not help either.

All comments welcome
john

 
Reply With Quote
 
 
 
 
gregarican
Guest
Posts: n/a
 
      03-09-2006
John N. Alegre wrote:

> I am trying to use net/smtp to send a mail message. What I am finding is
> that I can send a email message on the LAN but it never gets out to the
> world. What am I missing?


I think you are forgetting login credentials such as
....acct="username", passwd="password", authtype=:login as part of the
instance's construction.

 
Reply With Quote
 
 
 
 
John N. Alegre
Guest
Posts: n/a
 
      03-09-2006
gregarican wrote:

> I think you are forgetting login credentials such as
> ...acct="username", passwd="password", authtype=:login as part of the
> instance's construction.
>

but is this necessary???

When I set the SMTP server as host on mailers such as evolution or the Mac
OX X mailer I use no user / pass authorization. I just pass the mail to
that machine using SMTP. Why would this be different from Ruby code?
 
Reply With Quote
 
gregarican
Guest
Posts: n/a
 
      03-09-2006
John N. Alegre wrote:

> When I set the SMTP server as host on mailers such as evolution or the Mac
> OX X mailer I use no user / pass authorization. I just pass the mail to
> that machine using SMTP. Why would this be different from Ruby code?


Are you 100% sure there is no username/password combo stored in a
keychain or any other place on your Mac? If there is that's why the Mac
is automatically referencing this. Much like how my Outlook/Exchange
environment stores my information. But if I want to access raw SMTP
using Ruby I need to manually authenticate. Just a wild guess...

 
Reply With Quote
 
John N. Alegre
Guest
Posts: n/a
 
      03-09-2006
gregarican wrote:

> Are you 100% sure there is no username/password combo stored in a
> keychain or any other place on your Mac?


Yes there is nothing set in mailers from three different platforms. 2 other
linux boxes and one Mac (evolution or Mac Mailer) there is an "Trusted
Net:" entry in the firewall config but this would be the same for the code
as for the mailers.
...

 
Reply With Quote
 
John N. Alegre
Guest
Posts: n/a
 
      03-09-2006
another follow up.... the code I posted does not work from the same usr same
machine where login would not be necessary.

gregarican wrote:

> John N. Alegre wrote:
>
>> When I set the SMTP server as host on mailers such as evolution or the
>> Mac
>> OX X mailer I use no user / pass authorization. I just pass the mail to
>> that machine using SMTP. Why would this be different from Ruby code?

>
> Are you 100% sure there is no username/password combo stored in a
> keychain or any other place on your Mac? If there is that's why the Mac
> is automatically referencing this. Much like how my Outlook/Exchange
> environment stores my information. But if I want to access raw SMTP
> using Ruby I need to manually authenticate. Just a wild guess...


 
Reply With Quote
 
Logan Capaldo
Guest
Posts: n/a
 
      03-09-2006
--Apple-Mail-32-428678994
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed


On Mar 9, 2006, at 3:33 PM, gregarican wrote:

>
> Are you 100% sure there is no username/password combo stored in a
> keychain or any other place on your Mac? If there is that's why the
> Mac
> is automatically referencing this. Much like how my Outlook/Exchange
> environment stores my information. But if I want to access raw SMTP
> using Ruby I need to manually authenticate. Just a wild guess...


Are you sure you're not confusing SMTP with POP? You as a general
rule _don't_ have to authenticate with SMTP, although many SMTP
servers do have some form of authentication (e.g. require someone to
log in with POP first, etc.)


--Apple-Mail-32-428678994--


 
Reply With Quote
 
John N. Alegre
Guest
Posts: n/a
 
      03-10-2006

Logan Capaldo wrote:

>
> On Mar 9, 2006, at 3:33 PM, gregarican wrote:
>
>>
>> Are you 100% sure there is no username/password combo stored in a
>> keychain or any other place on your Mac? If there is that's why the
>> Mac
>> is automatically referencing this. Much like how my Outlook/Exchange
>> environment stores my information. But if I want to access raw SMTP
>> using Ruby I need to manually authenticate. Just a wild guess...

>
> Are you sure you're not confusing SMTP with POP? You as a general
> rule don't have to authenticate with SMTP, although many SMTP
> servers do have some form of authentication (e.g.┬*┬*require┬*someone┬*to
> log in with POP first, etc.)


Yes this is definately the case.┬*┬*I┬*obtained┬*a┬*Perl┬*script┬*that┬*sends┬*email
to the SMTP server I am trying to work with the Ruby code on and it works
fine after I change what I got to the hostname of the SMTP server.┬*┬*Greg┬*is
confusing POP with SMTP.

But back to the code.

Again I post my Ruby test code ...require('net/smtp')

################################################## ######
class Email
┬*┬*def┬*Email.send(date,┬*body,┬*server┬*=┬*'localhost',┬*port┬*=┬*25)
┬*┬*┬*┬*Net::SMTP.start(server,┬*port)┬*{┬*|mailer|
┬*┬*┬*┬*┬*┬*text┬*=┬*
┬*┬*┬*┬*┬*┬*"From:┬*info\n"┬*<<┬*
┬*┬*┬*┬*┬*┬*"To:┬*usr@domain\n"┬*┬*┬*┬*┬*┬*┬*<<
┬*┬*┬*┬*┬*┬*"Date:┬*#{date}\n"┬*┬*┬*┬*┬*┬*┬*┬*┬*┬*<<
┬*┬*┬*┬*┬*┬*"Subject:┬*New┬*entry┬*in┬*Database\n"┬*┬*┬*┬*┬*┬*┬*┬*<<
┬*┬*┬*┬*┬*┬*"Importance:┬*High\n"┬*┬*┬*┬*┬*┬*┬*┬*┬*┬*┬*<<
┬*┬*┬*┬*┬*┬*"MIME-Version:┬*1.0\n"┬*┬*┬*┬*┬*┬*┬*┬*┬*┬*<<
┬*┬*┬*┬*┬*┬*"Sender:┬*#{self.class.name}\n"┬*<<
┬*┬*┬*┬*┬*┬*"\n\n\n"┬*┬*┬*┬*┬*┬*┬*┬*┬*┬*┬*┬*┬*┬*┬*┬*┬*┬*┬*┬*┬*┬*┬*<<
┬*┬*┬*┬*┬*┬*body

┬*┬*┬*┬*┬*┬*mailer.send_message(text,┬*"info",┬*"usr@domain")
┬*┬*┬*┬*┬*┬*}
┬*┬*end

Email.send("#{Time.now}", "New entry in database at #{ Time.now}\n")
puts "end of code"
################################################## ######
This works to send mail to a user on the SMTP server machine.┬*┬*This┬*machine
has 30 users and I can send mail to any of those users, routed correctly.
Any email address outside the LAN disappers.

Here is the entry in the mail log:

endMar 10 09:21:31 libros postfix/smtp[24290]: 0F60E13FB0: host
mailfoundry-2.iphouse.net[216.250.188.211] said: 450 Domain in Reverse-Path
resolves to an invalid IP address (in reply to RCPT TO command)
Mar 10 09:21:33 libros postfix/smtp[24290]: 0F60E13FB0:
to=<(E-Mail Removed)>, relay=mailfoundry-1.iphouse.net[216.250.188.210],
delay=4, status=deferred (host mailfoundry-1.iphouse.net[216.250.188.210]
said: 450 Domain in Reverse-Path resolves to an invalid IP address (in
reply to RCPT TO command))

so the domain, even though it is correct is somehow being munged by Ruby to
something that the downstream realy does NOT understand. (here
http://www.velocityreviews.com/forums/(E-Mail Removed) is the valid email address I used in the code.

?????????????????????????
john
 
Reply With Quote
 
John N. Alegre
Guest
Posts: n/a
 
      03-10-2006
For anyone who has been following this thread I have solved the problem.
Well I guess a better term is there never was a problem. Two months ago I
changed IPs and got a new block of static IPs. The entry for reverse DNS
lookup on the mail software they use was set to require reverse DNS for
email. Things like evolution or the Macintosh OS X mailers do reverse DNS
so those things worked fine. The raw code however did not handle revers
DNS so the mail send failed. Once they changed the entry the code shown
below will send mail out just fine.

Hope this helps someone else.

Peace
john

John N. Alegre wrote:

> I am trying to use net/smtp to send a mail message. What I am finding is
> that I can send a email message on the LAN but it never gets out to the
> world. What am I missing?
>
> Here is my test code:
> ################################################## ##################
> require('net/smtp')
>
> class Email
> def Email.send(date, body, server = 'localhost', port = 25)
> Net::SMTP.start(server, port) { |mailer|
> text =
> "From: info\n" <<
> "To: usr@domain\n" <<
> "Date: #{date}\n" <<
> "Subject: New entry in Database\n" <<
> "Importance: High\n" <<
> "MIME-Version: 1.0\n" <<
> "Sender: #{self.class.name}\n" <<
> "\n\n\n" <<
> body
>
> mailer.send_message(text, "info", "usr@domain")
> }
> end
>
> end
>
> Email.send("#{Time.now}", "New entry in database at #{ Time.now}\n")
> puts "end of code"
> ################################################## ##################
> on the LAN SMTP server with 'localhost' and usr@domain being a user on the
> same machine WORKS OK ... with 'localhost' replaced with 'machine' where
> machine is the machine on the LAN that sends SMTP mail and usr@domain is a
> user on that same machine and the code is run anywhere on the LAN it WORKS
> OK to a user on 'machine' ...
>
> HOWEVER ...
>
> if usr@domain is outside the LAN the mail never gets sent either if the
> code is run on 'localhost' or on a machine on the LAN with 'machine'
> replaced by
> the IP of the SMTP server. I know 'machine' will serve as a SMTP host for
> mailers such as evolution or Mac OX X mailer because I use it for that all
> the time.
>
> What am I missing.
>
> I know I could go to a better Ruby package such as TMail or RubyMail or
> bring out the cannons and use ActionMailer but if I don't understand what
> is happening at this basic level that might not help either.
>
> All comments welcome
> john


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
outside type, outside function Krzysztof Poc C++ 1 02-07-2012 04:06 PM
Pix 506e w/5 static outside IPs - How to create a rule to allow ALL tcp/udp traffic from one outside IP to an internal IP (for an internal router/NAT with it's own subnet) kyoo Cisco 22 04-12-2008 03:37 PM
help with pix inside->outside + dmz->outside + inside->outside->dmz Jack Cisco 0 09-19-2007 01:57 AM
CallForward outside->inside->outside failed after one ring. Yogz Cisco 1 04-16-2007 03:58 PM
nat from outside to outside dt1649651@yahoo.com Cisco 1 08-21-2005 04:26 PM



Advertisments