Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

How to sendmail using Perl in WindowXP

by britney (Acolyte)
on Jan 25, 2007 at 22:05 UTC ( [id://596637]=perlquestion: print w/replies, xml ) Need Help??

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

I am new with Perl and using in Windows, I have leanred how to send mail in UNIX, but in Windows I am not sure.

I have a file like record.pl, it have no perl/lib

#!c:/progra~1/perl/bin/perl.exe ...... print SUMMARY "\n"; print SUMMARY "Results Summary\n"; print SUMMARY "------- -------\n"; print SUMMARY "Total: $globaltotal\n"; print SUMMARY "Passed: $globalpassed\n"; print SUMMARY "Failed: $globalfailed\n"; close (SUMMARY);

------------

I would like to mail the file in SUMMARY to my email, what should I add. Thanks for helping me.

20070126 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips

Replies are listed 'Best First'.
Re: How to sendmail using Perl in WindowXP
by shonorio (Hermit) on Jan 25, 2007 at 23:53 UTC
    The easier way, and way that I use on my systems, is with Net::SMTP if you have a SMTP server on you enviroment. The other way is to use OLE to talk with Outlook or any other email client, but this is the hard way, very hard :)

    Solli Moreira Honorio
    Sao Paulo - Brazil

      For a higher-level abstraction, also consider Email::Send.

      From the synopsis:

      use Email::Send; my $message = <<'__MESSAGE__'; To: recipient@example.com From: sender@example.com Subject: Hello there folks How are you? Enjoy! __MESSAGE__ my $sender = Email::Send->new({mailer => 'SMTP'}); $sender->mailer_args([Host => 'smtp.example.com']); $sender->send($message);

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: How to sendmail using Perl in WindowXP
by Tanktalus (Canon) on Jan 26, 2007 at 00:36 UTC
Re: How to sendmail using Perl in WindowXP
by chargrill (Parson) on Jan 26, 2007 at 00:16 UTC

    Here's one way. Please note that this was just pulled from some code I had lying around that sends an email through outlook (contrary to some of my contemporaries it wasn't really all that hard ;-) - as such, there are a few functions referenced in this snippet that are not provided.

    my( $outlook, $message ) = open_outlook(); build_email( $message, $maindate, $file ); send_email( $message ); sub build_email { my( $message, $date, $file ) = @_; my $displaydate = format_date( $date ); $message->{'To'} = q{toaddress@domain.com}; $message->{'Subject'} = q{This is the subject}; ( $message->{'Body'} =<<" EOBODY" ) =~ s/^ //gm; blah blah blah EOBODY my $attachment = $message->Attachments(); $attachment->Add( $file ); return 1; } sub send_email { my $message = shift; $message->Send(); return 1; } sub open_outlook { my $outlook = Win32::OLE->GetActiveObject( 'Outlook.Application' ) || Win32::OLE->new( 'Outlook.Application', \&OleQuit ) || die "can't create Outlook.Application: is it installed? : $! +: $^E"; my $message = $outlook->CreateItem(0) || die "can't create new message : $! : $^E"; return( $outlook, $message ); }


    --chargrill
    s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)
Re: How to sendmail using Perl in WindowXP
by Discipulus (Canon) on Jan 26, 2007 at 08:47 UTC
    here using CDO that now ship with xp e 2k3 instead of CDONTS. This code run without an SMPT on local machine specifiing a mail server.
    #!perl use strict; use warnings;#amen use Win32::OLE ; my $Message = Win32::OLE->new("CDO.Message"); #francobollo means stamp... my $francobollo= Win32::OLE->new ("CDO.Configuration") ; $francobollo->{Fields}->{"http://schemas.microsoft.com/cdo/confi +guration/sendusing"}=2;#means with no local SMTP srv $francobollo->{Fields}->{"http://schemas.microsoft.com/cdo/confi +guration/smtpserver"}="mail.server.you.can.use.net"; $francobollo->{Fields}->{"http://schemas.microsoft.com/cdo/confi +guration/smtpserverport"}=25; $francobollo->{Fields}->Update(); $Message->{Configuration} = $francobollo; $Message->{From}="me\@peacefull-place.org"; $Message->{To}="you\@in-a-dog-hell.com"; $Message->{Bcc}="your-assistant\@angel.net"; $Message->{Subject}="I told you, myDeamon, to run on a Linux machine." +; $Message->{TextBody}="ah ahah ahaha aha ahhha \n"; $Message->Send();
    HTH Lorenzo*
Re: How to sendmail using Perl in WindowXP
by EvanK (Chaplain) on Jan 26, 2007 at 15:33 UTC
    there is also a commercial sendmail equivalent for windows (google it), but from my experience its more trouble than its worth. Net::SMTP is the better choice, as other monks have suggested.

    __________
    The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.
    - Terry Pratchett

      Thanks for all of your advice, I will try and let you know the result
Re: How to sendmail using Perl in WindowXP
by aplonis (Pilgrim) on Jan 30, 2007 at 02:07 UTC

    Been a while since I used it, but I used to do it
    like this...

    My Script Here

    ...for monitoring ongoing tests from my home an hour away.

    That script checks a log file every N minutes for updates,
    then emails it if changed. Steal anything you want out of
    there if it suits your needs.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://596637]
Approved by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-24 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found