Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Win32/Outlook Mail Forwarder

by Guildenstern (Deacon)
on Aug 24, 2000 at 23:50 UTC ( #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);

Comment on Win32/Outlook Mail Forwarder
Download Code

Back to Code Catacombs

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (13)
As of 2014-09-18 08:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (109 votes), past polls