Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Send email on Windows Server

by Anonymous Monk
on Jan 18, 2007 at 23:51 UTC ( #595383=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have been using Mail-Sendmail module in my Perl 5.8 scripts for sending email in the past but now I am working on a Windows 2000 server that doesnt have the Mail-Sendmail module. The server admins will not load the module so I have to use another way to send emails.

Please advise how I can send email from my Perl script on a Windows 2000 server that does not have Mail-Sendmail module.

Replies are listed 'Best First'.
Re: Send email on Windows Server
by liverpole (Monsignor) on Jan 19, 2007 at 00:21 UTC
    You don't need to install the module; you can just use it locally (assuming of course that you are allowed to do so on your machine).

    I had never used Mail::Sendmail, but I looked at the source on CPAN, and there's nothing prohibiting you from using it in a local directory.

    Just for fun, I took a copy of it, renamed it as Postal\, (modifying the package name within the file to Postal::Dispatch too, of course), and ran the following program:

    #!/usr/bin/perl -w # # Test of local copy of Mail::Sendmail (renamed as Postal::Dispatch # to be sure it works on its own :-)). # use strict; use warnings; use Postal::Dispatch; my %mail = ( To => '', From => '', Message => 'Hello to myself from Postal::Dispatch', ); sendmail(%mail) or die $Postal::Dispatch::error; print "OK. Log says:\n", $Postal::Dispatch::log;

    And sure enough, I got the mail it sent to my ISP!

    The only other change I had to make was to the %mailcfg hash in the Mail::Sendmail module:

    'smtp' => [ qw( localhost ) ]

    which I had to change, of course, to:

    'smtp' => [ qw( ) ]

      Thanks, but I have to run this script on our Server and can not run it locally. Please advise.

        You are writing a program and putting it on the server, right? You can include the source for Mail::Sendmail in your script...then you would leave out the 'use Mail::Sendmail' line, of course.

        Also, not installing modules is stupid. What if you wrote a module with code that you wanted to reuse? Would they install that, or would you have to include the source in every script you wrote?

Re: Send email on Windows Server
by Thelonius (Priest) on Jan 19, 2007 at 00:17 UTC
    You can connect to an SMTP server to send mails using modules such as Net::SMTP, Mail::Mailer::smtp, or Mail::Transport::SMTP.

    The SMTP server can be on the same Windows box or can be on any other server that you can access and that allows you to send mail. I believe that Windows 2000 Server comes with bundled SMTP software. Your company almost certainly has an SMTP server that, with the proper security configuration, you can use.

    You do have to handle the possibility that the SMTP server is not working/reachable when you try to send mail. If the server is on the same box, this is less likely (no network issues), but of course can still happen. Depending on your application, you can handle this either before or after the mail is generated. E.g. if you're generating the mail from a database of addresses, you can just regenerate from the database rather than saving the generated emails for retry. (Avoid sending duplicates, of course.) If you're sending emails based on, say events on a web server, it's a little more problematic.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2018-05-24 02:50 GMT
Find Nodes?
    Voting Booth?