Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
PerlMonks : A module to send an email without your ISP's mailserver

by gaggio (Friar)
on Jul 28, 2000 at 18:15 UTC ( #24850=CUFP: print w/replies, xml ) Need Help??

Well, I could have probably posted this in the Code Catacombs section, but I do think that it is also a Cool Use for Perl, even a small revelation for some people...

Indeed, there were mail sending modules available (Mail::Mailer, Net::SMTP, etc.), and there was the mail program forking method (e.g. open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq"), etc.). Those methods are not as simple as sending an email could be, because you need to have a mailserver to route your email through the Internet (I am not even talking about the Win32 case, where you need to get some sort of sendmail replacement to work along with those modules...).

Well, maybe that is for you, then, since the only thing it requires is to have an Internet connection, which you have obviously since you are reading this :-)

I can see already some people coming and telling me that it is not "the holiest way" to send email, because the netiquette or "net moral policy" forbids it. Well, first, I am not the only one to send email like this (have a look here, for example, where you can download and use for FREE an application to send your email directly to your target email address from a Microsoft platform). Second, I don't understand why sending emails that way would perturb in any way the way the Internet is working. I think that no harm can be done by bypassing your ISP, when you can: it just makes the route of the emails shorter, in fact!

There is not lots of technology behind Ultimail. It simply uses a raw socket connection to talk directly to the server of the email receiver, after having fetched this server name in the DNS records.

Warning: Althoug I did not have any problem using the module myself, I do *not* guarantee that sending emails that way will work always. Simply because it is possible that some email servers would performs special checks during the communication. For example, if you want to send an email with a "From:" field claiming that you are "" - a fake email address for the sender - you might find your sending request denied.

So, here you are, excited about such possibilities, and want to use the module. How can you do that? - Easy. First, go to my homepage, follow the link to the Perl section, download the module, unzip it, and put it in your library directory. Note that to get the program to run, you will have to install the Net::DNS module. The Net::DNS Author can be found here. If you are on a Microsoft platform, you should download the latest development version, to avoid problems. Then, code! Here's a self explanatory example program:

#!/usr/local/bin/perl -w use Ultimail; my $um = Ultimail->new; $um->mailto('Larry Wall <>'); $um->mailfrom('Me <>'); $um->subject("The beauty of"); $um->body(" is one of the most beautiful creation of all +time (after Perl itself, of course :-)."); $um->send;

There are other features in the module, like the possibility to display the communication, with the verbose() method, or the possibility to give a "ReplyTo" email address different from the sending address, but I leave this undocumented here, to keep it simple: just read the code by yourself! does not support Attachments, yet. Feel free to add the feature to the module, if you want - you will certainly need to use an encoding library. But in this case, please email me: I'd be glad to see your improvements in action!
  • Comment on : A module to send an email without your ISP's mailserver
  • Download Code

Replies are listed 'Best First'.
RE: : A module to send an email without your ISP's mailserver
by merlyn (Sage) on Jul 28, 2000 at 18:33 UTC
      You are right, I forgot to mention that there was Net::SMTP also. I actually used Net::SMTP, but had problems with it. It might be because I was on a Win32 machine? I don't know. All I know was that it would not send email the way does. I also tried their example of running an SMTP server, but it did not work either :-)

      I decided that I would write my own, then, this is as simple as that. is very simple (a lot simpler than Net::SMTP), and does the job on Win32 machines (I did not test it on *nix platforms, but it should be pretty slick there also).

        I've had nothing but success using Net::SMTP under Perl 5.005_03 under Windows NT.

        I would like to point out that while endeavoring to learn the intricacies of SMTP is a Good Thing, there are a number of quirky SMTP servers in the world. Net::SMTP knows about most of them, and is a tried and trusted module. Be aware that it's quite likely you'll run into one of these servers sooner or later. And knowing the Murphy effect, it'll be the first time a user tries to use your module... (happens to me all the time!)


        e-mail jcwren
        If you "had problems", what were they? And were you using the latest ActiveState Perl?

        -- Randal L. Schwartz, Perl hacker

        update: OK, as feedback for me, why was this voted down? I was genuinely curious about the unspecified problems, since I'm using Net::SMTP in programs I write. Should I have remained uninformed?

        Or is this just a backlash fallout from the other posts of the past few days?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://24850]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2018-06-21 19:05 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (118 votes). Check out past polls.