Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello How Can I send Email using perl, directly from my PC without the need of external smtp server, so I can deliver the Email message directly to the recipent's mail server "hotmail.com". Do I need to have a mail server on my PC? Is there any perl module acts as a mail server? Mourad Selim
  • Comment on Send Mail form my PC without using smtp server?

Replies are listed 'Best First'.
Re: Send Mail form my PC without using smtp server?
by hardburn (Abbot) on Mar 28, 2005 at 21:23 UTC

    You can run an MTA on your own machine (common on *nix machines). You have to hit an SMTP server at some point.

    "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Re: Send Mail form my PC without using smtp server?
by jhourcle (Prior) on Mar 28, 2005 at 23:51 UTC

    You have two basic options --

    1. Run an SMTP server locally.
    2. Deliver directly to the recipient's mail server

    If you're running a server locally, it doesn't have to listen to on a port. You can configure some mail programs (sendmail being the standard, but I've also done it with postfix), so they're running as a daemon, and accept local delivery, and will handle the processing. (including requeuing on failed delivery attempts). I typically do this on any desktop, as you can have times when a cron job fails delivery, and it just gets left in the mailqueue.

    If you attempt to handle the delivery directly, you can use Net::SMTP to connect to the server and drop off the mail. However, you'll need to determine the correct MX server to drop off the mail. (see Net::DNS). Remember, however, that you'll be responsible for any requeuing that might be necessary.

    Please also be aware that many sites are using multiple layers of spam filtering, both on the inbound and outbound. Your network may not allow port 25 connections out, and if you're connecting through an ISP, your netblock may be flagged as a dialup (or similar, non-fixed) connection, and the message could be dropped on receipt, without a response.

Re: Send Mail form my PC without using smtp server?
by muba (Priest) on Mar 28, 2005 at 21:35 UTC
Re: Send Mail form my PC without using smtp server?
by TedPride (Priest) on Mar 29, 2005 at 04:52 UTC
    You can run your own SMTP server and send through that. It's not hard to find a free one. However, a lot of hosts will reject email coming from a dynamically generated IP, so if the mail really has to get there, it's better to feed it through a remote hosting account with a domain name. The hoster may kill your account if you're caught spamming, however, so you better be dang sure the people receiving the emails want to receive them, and that you don't overload their mail server by bombing it with thousands of emails all at once.
Re: Send Mail form my PC without using smtp server?
by kprasanna_79 (Hermit) on Mar 29, 2005 at 04:49 UTC
    u can start Send mail locally.
    This will act like a smtp server and u can use MIME::Lite or Net::SMTP as mail client.
    These two perl modules are used widely for mail client.
    See also other mail clients in cpan
    --prasanna.k
Re: Send Mail form my PC without using smtp server?
by willyyam (Priest) on Mar 29, 2005 at 15:32 UTC

    I might also suggest Mail::Mailer. Here is a proof-of-concept program for you to look at that acts as a Perl-based email transmission client:

    #!/usr/bin/perl -w use Mail::Mailer; $smtp = Mail::Mailer->new("smtp","Server","smtp.server"); print "To: "; $to = <STDIN>; chomp($to); print "Subject: "; $subject = <STDIN>; chomp($subject); print "Body:\n"; while ($line = <STDIN>) { last if $line eq ".\n"; $body .= $line; } chomp($body); print "Opening SMTP connection...\n"; $smtp->open({ "From" => "email\@example.com", "To" => $to, "Subject" => $subject }); print $smtp $body; print "Sending email...\n"; $smtp->close() or die "Can't close mailer: $!"; print "Mail sent.\n";

    Obviously, using strict is recommended.