1f77 Emailing from Perl on Windows platforms - Perl Programming
Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Emailing from Perl on Windows platforms

Posted by admin (Graham Ellis), 11 February 2006
Perl doesn't include built-in emailing functions.  On Unix or Linux boxes, I've always put in calls to the local sendmail program and that works just fine, but there's no sendmail on Microsoft boxes ...

Alternative - use a CPAN module (or rather a module that you can download with ppm);   here's the "engine" of a program that I wrote a s demo in the last couple of days:

Code:
use Mail::Sendmail;

%mail = (To => 'graham@sheepbingo.co.uk',
From => 'Graham Ellis <graham@wellho.net>',
Message => "First line\nSecond line\netc\n",
Subject => "Perl email from Windows",
Reply-to => 'graham@wellho.net',
smtp => 'lightning.he.net');

$aok = sendmail(%mail);


See Complete example and further documentation

Posted by aparks (aparks), 25 May 2006
You might also use MIME::Lite (also up on CPAN) if you need to attach files to your email. We use this for firing off server logs to a central email account (which we then ignore like all good sysadmins )

Code:
use MIME::Lite;

my($mailServer) = 'smtp.company.com';
my($mailFrom)   = 'adrian@mycompany.com';
my($mailTo)      = 'someoneelse@mycompany.com';
my($realName)   = "Adrian";
my($subject)    = "Subject of message";
my($body)      = "Body of message"
my ($file)      = "c:\\temp\\file.fil";

my $msg = MIME::Lite->new(

     From=>"$mailFrom",
     To => "$mailTo",
     Subject=>"$subject",
     Type=>'multipart/mixed');

     $msg->attach(      Type      =>'TEXT',
                 Data      =>"$body");
     
     
     $msg->attach(      Type      =>'TEXT',
                       Path      =>"$file",
                       Disposition => 'attachment');


MIME::Lite->send('smtp', "$mailServer",Timeout=>60);

$msg->send;


Wow - finally I've contributed something back to OpenTalk (well hopefully anyway). I've been feeling guilty about all the unrequited help I've had from here over the years...



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.
fb4a

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2013: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho
0