Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Win32/Outlook Mail Forwarder

by Guildenstern (Deacon)
on Aug 24, 2000 at 23:50 UTC ( [id://29527]=sourcecode: print w/replies, xml ) Need Help??
Category: Win32 Stuff
Author/Contact Info Chad Johnston cjohnston@rockstardevelopment.com
Description: Forwards email messages saved to text from MS Outlook (requires 3rd party DLL, unfortunately) to my web phone so I can be in touch when out of cube.
# Procmail.pl
# Monitors a directory for new saved emails
# Emails are in text format saved from Outlook
# Other progs may save in slightly different format - YMMV
# Required fields in email are - 
# From: xxxxx [xxxxx@xxxx.xxxx]
# Subject: xxxxx xxxxx xxxxx
# File name is year-mo-da-hhmmss.txt - used for determining # time of 
+email

use Strict;
use Win32::ChangeNotify;

$indir = "x:/xxx/xxx"; #dir for saved messages
$status = "procstat.txt"; #status file

$notify = Win32::ChangeNotify->new($indir, 0, FILE_NAME);
open(STATUS, ">>".$status) or die "Error opening stats file: $!\n";

my $now = localtime; #start time
print STATUS "Procmail started: $now\n"; 
my $nummail = 0; #number of mails processed
my $done = 0; #done processing (back at desk)?
while (!($done))
{
 $notify->wait or warn "Problem waiting: $!\n"; #wait for files
 if (-e $indir . "/.stopmail") # file created to signal stop
 {
      $done = 1;
    unlink($indir . "/.stopmail");
 }

 opendir(INDIR, $indir) or die "Error opening directory: $!\n";
 my @mail = grep { $_ ne '.' and $_ ne '..' } readdir INDIR;
 foreach (@mail)
 {
    my $from = "";
    my $subject = "";
    my $time;
    open(INFILE, "<". $indir . "/" . $_) or die "Could not open file: 
+$!\n";
    while ($next = <INFILE>)
    {
         chomp($next);
        if ($next =~ /^From:/)
        {
          if ($from eq "") # Only set from if empty to avoid problems 
+with forwards
          {
           $next =~ /.*\[(.*)\].*/;
           $from = $1;
           $from = (split(/:/,$from))[1];
          }
        }
        elsif ($next =~ /^Subject:/)
        {
          if ($subject eq "") # Set subject if empty to avoid probs wi
+th forwards
          {
           $next =~ /^Subject: *(.*)/;
           $subject = $1;
           for ($subject)
           {
               s/^\s+//;
           }
          }
        }
       }
    /(.*)\.txt/; # Get time from file name
    $time = $1;

        # Compose message info
        # My phone is limited, so only the facts
    my $msg = "From: $from\nSubject: $subject\nTime: $time\n";
   
        # Blat works best using a file
    if (open(OUTMP, ">" . $time . ".tmp"))
    {
     print OUTMP $msg;
     close(OUTMP);

     my $blatcmd = "c:\\blat\\blat.exe " . $time . ".tmp -s \"New Emai
+l\" -t xxxxxxxx\@xxxx.xxx.com";

     print STATUS "Blatted:\n";
     my $blatres = `$blatcmd`;

     print STATUS "$blatres\n";
     unlink($time . ".tmp");
     $nummail ++;
    }
    close(INFILE);
    unlink($indir . "/" . $_);
 }
 undef(@mail);
 sleep(1);
 closedir(INDIR);
 $notify->reset; # Wait for next file(s)
}
$notify->close;
$now = localtime;
print STATUS "Caught stop message: $now.\n";
print STATUS "$nummail messages processed\n\n";
close(STATUS);

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-03-28 07:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found