Simple SMTP server in ruby

M

mad joker

[Note: parts of this message were removed to make it a legal post.]

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, '(e-mail address removed)', '(e-mail address removed)'

smtp.finish

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

Brian Candler

mad said:
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, '(e-mail address removed)', '(e-mail address removed)'

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.
 
P

pharrington

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










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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

send email in ruby 12
Mail Using SMTP Problem 2
SMTP Server Connection Errno ETIMEOUT 0
Problem with SMTP mail program 3
net/smtp 6
net/smtp 3
Need to build smtp server in Ruby? 1
SMTP SMS Reminder Script 5

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top