J
John N. Alegre
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
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