Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl Direct SMTP Server

Status
Not open for further replies.

Kirsle

Programmer
Jan 21, 2006
1,179
0
0
US
An old question of mine that keeps resurfacing every now and then is this:

Is it possible to create a "direct-send" SMTP server using Perl?

Last time I checked this out, the SMTP server modules on CPAN would act as relay servers... they could receive requests to send e-mails out, but they wouldn't literally send them. They'd redirect them through another SMTP server which can send them.

The closest way I found to do this was to use Net::DNS to look up the DNS information of the domains of the recipients, and from that, get their MX records and go through the SMTP process. But this didn't seem to work very efficiently. Yahoo Mail users, for instance, would have a difficult time receiving e-mails sent from such a server setup.

I've downloaded other personal SMTP servers that I use which can directly send e-mails out, and they send to Yahoo Mail users just fine.

Here are the modules I've played around with:

Net::SMTP::Server acts as an SMTP server and can save incoming messages. It doesn't seem to be able to send them out though. It uses Net::SMTP::Server::Relay to send outgoing messages which, again, is a relay server.

Net::SMTP::Server::Relay uses Net::DNS to look up MX records, which, last time I checked, doesn't work well with Yahoo Mail (I haven't done extensive testing against other domains yet).

Has anyone managed to make an outgoing e-mail server in Perl?
 
Yes, its pretty easy... it can be done in a very few lines i suppose. The algo for this should be like this:
Code:
my $mx = Net::DNS ( "MX" Record(s) by weight || "A" Record ); #`dnsmx domain` if you have djbdns
my $sock = socket ( $mx, port(25) );
if ( /banner greeting/ ) 
{
Print to $sock, SMTP Commands: RSET, MAIL FROM, RCPT TO, DATA, Period.
}
I think that's about it for sending. Receiving should also be easy but its lengthy because you'd have to follow the whole RFC guidelines on what your client may ask.

The obvious disadvantage of this are 1) there is no retrying temporary failures 2) MX/A records are not cached 3) Only one process can run at a time unless you're forking 4) Its slow compared to compiled code and takes a lot more memory 5) Non-standard compliant regards to commands like PIPLELINING, etc.

But even with all the disadvantages the bottom line is it does get the work done. So, don't you just love Perl? [pipe]

HTH


---
cheers!
san
smoking3vc.gif


print length "The answer to life, universe & everything!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top