3 # Uploader: upload one or more RFC822-format messages in the specified
4 # directory to a (local) SMTP server for on-delivery.
6 # Written by Ewen McNeill, 18/11/1997.
8 # This program scans the specified directory for messages to send (all
9 # files in the directory are considered to be messages). Any messages
10 # that are found are instantiated as Mail::Internet objects, and then
11 # delivered with SMTP to the local SMTP server.
13 #---------------------------------------------------------------------------
17 use DirHandle
; # Directory handling
18 use Net
::SMTP
; # Simple Mail Transfer Protocol
20 require "sendconf.ph"; # Sender configuration information
22 #---------------------------------------------------------------------------
26 # SendMessage: expects filename of message to send (and that the file will
27 # exist in the outbound directory).
29 # Sends the message to the SMTP server for on-delivery, and if that is successful
30 # moves the original file into the sent area.
32 # Returns 1 if the file is delivered to the SMTP server, and 0 otherwise.
37 die "No file to send\n" if (! defined($filename));
39 if ( ! open(MSG
, "<$SendConf::outgoing/$filename") )
41 warn "Unable to open \"$SendConf::outgoing/$filename\" -- skipping file\n";
45 # Note: need to specify who to say on the HELO line, because Windows isn't
46 # particularly good at figuring it out.
47 my $smtp = Net
::SMTP
->new($SendConf::SMTPserver
,
48 Hello
=> $SendConf::myhostname
);
51 warn "Cannot contact SMTP server: $SendConf::SMTPserver\n";
52 warn "Skipping file: $filename\n";
58 # Do the envelope stuff
59 $rc = $smtp -> mail
($SendConf::myemail
);
61 { warn "Error encountered sending envelope from\n"; }
64 $rc = $smtp -> to
($SendConf::theiremail
);
66 { warn "Error encountered sending envelope to\n"; }
69 $rc = $smtp -> to
($SendConf::copyemail
);
71 { warn "Error encountered sending envelope cc\n"; }
77 warn "Cannot start mail. Abandoning mail transfer ($filename).\n";
87 warn "Problems starting message data ($filename). Abandoning transfer.\n";
95 $rc = $smtp->datasend($_);
97 { warn "Problems sending data line: $_\n";
98 warn "Attempting to continue.\n"; # XXX -- is this wise?
101 $rc = $smtp->dataend();
103 { # Message was delivered correctly, tidy up.
107 unlink("$SendConf::outgoingprocessed/$filename") &&
108 warn "Removed older copy of \"$filename\" from processed directory\n";
110 rename("$SendConf::outgoing/$filename",
111 "$SendConf::outgoingprocessed/$filename") ||
112 warn "Message transfered correctly, unable to move out of way ($filename)\n";
117 { # Problems sending the message -- leave it alone.
121 warn "Problems sending message ($filename). Leaving to try again later.\n";
127 #---------------------------------------------------------------------------
131 # Check configuration values are set
133 die "No outgoing directory" if (! defined($SendConf::outgoing
));
134 die "No processed directory" if (! defined($SendConf::outgoingprocessed
));
135 die "No SMTP server" if (! defined($SendConf::SMTPserver
));
136 die "No local email address" if (! defined($SendConf::myemail
));
137 die "No remote email address" if (! defined($SendConf::theiremail
));
138 die "Who am I anyway?" if (! defined($SendConf::myhostname
));
140 # Scan the directory for files to process, and if there are any process them
143 my $numprocessed = 0;
145 my $dir = new DirHandle
$SendConf::outgoing
;
148 #print "Scanning directory: ", $SendConf::outgoing, "\n";
150 while (defined($file = $dir->read))
152 if (-f
"$SendConf::outgoing/$file")
153 { if (sendmessage
($file))
160 warn "Unable to read from directory: ", $SendConf::senddir
, "\n";
161 print "0 files processed.\n";
165 if ($numprocessed != 1)
166 { print "$numprocessed files processsed.\n"; }
168 { print "1 file processed.\n"; }