Simple SMTP server in ruby

Hi,
I was trying a simple mail smtp server in ruby. I tried the code
in
the following link

http://snippets.dzone.com/posts/show/3932

I am unable to send mail to my gmail account from the server. Can you
please
tell What may be the reason?
I dont want to use any SMTP servers like ( sendmail or qmail) .I used
the
code in the link as server.rb.
I tried using the following simple code

msgstr = <<END_OF_MESSAGE
From: joker [email protected]
To: some [email protected]
Subject: test message
Date: Sat, 23 Jun 2001 16:26:43 +0900
Message-Id: [email protected]
This is a test message.
END_OF_MESSAGE

require ‘net/smtp’

smtp = Net::SMTP.start(‘127.0.0.1’, 25)

smtp.send_message msgstr, ‘[email protected]’, ‘[email protected]

smtp.finish

Yes my email address are changed… But even if i give correct mail
address.
I am not able to send.

mad joker wrote:

Hi,
I was trying a simple mail smtp server in ruby. I tried the code
in
the following link

http://snippets.dzone.com/posts/show/3932

I am unable to send mail to my gmail account from the server. Can you
please
tell What may be the reason?

That’s because a SMTP server receives mail. If you want to send mail,
you need a SMTP client.

I tried using the following simple code

msgstr = <<END_OF_MESSAGE
From: joker [email protected]
To: some [email protected]
Subject: test message
Date: Sat, 23 Jun 2001 16:26:43 +0900
Message-Id: [email protected]
This is a test message.
END_OF_MESSAGE

require ‘net/smtp’

smtp = Net::SMTP.start(‘127.0.0.1’, 25)

smtp.send_message msgstr, ‘[email protected]’, ‘[email protected]

smtp.finish

Yes my email address are changed… But even if i give correct mail
address.
I am not able to send.

What error do you get?

That code sends outbound mail to a mailserver running on your local
machine (127.0.0.1). Do you have one running there, e.g. sendmail, exim,
postfix? If no, then you should get a fail to connect error. If yes, and
the mail is sent, then you’ll need to look in your mailserver logs to
see why it didn’t get delivered further.

Or you could replace 127.0.0.1 with your ISP’s SMTP relay hostname.

On Mar 11, 3:42 pm, Brian C. [email protected] wrote:

tell What may be the reason?
msgstr = <<END_OF_MESSAGE
smtp = Net::SMTP.start(‘127.0.0.1’, 25)

That code sends outbound mail to a mailserver running on your local
machine (127.0.0.1). Do you have one running there, e.g. sendmail, exim,
postfix? If no, then you should get a fail to connect error. If yes, and
the mail is sent, then you’ll need to look in your mailserver logs to
see why it didn’t get delivered further.

Or you could replace 127.0.0.1 with your ISP’s SMTP relay hostname.

Posted viahttp://www.ruby-forum.com/.

An SMTP server definitely sends email. However two problems…

  1. If you just copy/pasted the code from that page, the server is
    listening on port 1234, while you’re trying to connect to port 25.
  2. THAT server does not actually send email. It’s not meant to send
    email; the code seem more a simple example of how to use GSever.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs