#!/usr/bin/perl # # Command: perl email.pl "%1" "%2" "%4" # # Call: perl email.pl Scriptpath Spoolpath Filename # use strict; use warnings; use MIME::Lite; use Template; #------------------------------------------------------------------------------# my $Script = $ARGV [0]; # Params: Scriptpfad Spoolpfad Dateiname my $Spool = $ARGV [1]; my $Name = $ARGV [2]; my $PCLFile = $Spool . "\\" . $Name . ".pcl"; my $CTLFile = $Spool . "\\" . $Name . ".ctl"; my $PDFFile = $Spool . "\\" . $Name . ".pdf"; my $PJLFile = $Spool . "\\pjl.pjl"; my ($Anschrift1, $Anschrift2, $Anschrift3, $Anschrift4, $Bestellnummer, $Liefernummer, $Id, $mail_html, $mail_text); open (CTL, "<$CTLFile") or die "Kann $CTLFile nicht finden\n"; # Auf gültige Kontrolldatei prüfen --------------------------------------------# $Id = ; $Id = ; chomp ($Id); unless ($Id =~ /\[p2f\].*/) { die("Keine gültige Kontrolldatei"); } # Daten aus Kontrolldatei auslesen --------------------------------------------# while() { chomp; if (/^\[0102C10000\] +([0-9]+).*/) { $Liefernummer = $1; } if (/^\[0104290000\]/) { $Bestellnummer = substr ($_, 69, 5); } if (/^\[0103750000\]/) { $Anschrift1 = substr ($_, 12, 50); } if (/^\[0103B10000\]/) { $Anschrift2 = substr ($_, 12, 50); } if (/^\[0104290000\]/) { $Anschrift3 = substr ($_, 12, 50); } if (/^\[0104650000\]/) { $Anschrift4 = substr ($_, 12, 50); } if (/^\[0104A10000\]/) { last; } } close (CTL); # Lieferschein als PDF-Datei erzeugen -----------------------------------------# open my $fh, ">:raw", $PJLFile; print $fh "\x1b%-12345X\x0A" . "\x40PJL DEFAULT PDFMARK = \"[ " . "/Author (Meine Firma) " . "/Creator (print2forms) " . "/Keywords (Lieferschein, " . $Liefernummer . ") " . "/Title (Lieferschein " . $Liefernummer . ") " . "/DOCINFO pdfmark \""; close ($fh); my $Document = $Spool . "\\LI-" . $Liefernummer . ".pdf"; my $Cmd = "\"" . $Script . "\\gpcl6win64.exe\"" . " -dNOPAUSE" . " -sDEVICE=pdfwrite" . " -dPDFFitPage" . " -dPDFA=1" . " \"-sOutputFile=" . $Document . "\"" . " \"" . $PJLFile . "\"" . " \"" . $PCLFile . "\""; system ($Cmd); # Variablen für Schablonen vorbereiten ----------------------------------------# my $tt = Template->new (); my %params = (Anschrift1 => $Anschrift1, Anschrift2 => $Anschrift2, Anschrift3 => $Anschrift3, Anschrift4 => $Anschrift4, Bestellnummer => $Bestellnummer); $tt->process ('mail.html', \%params, \$mail_html); $tt->process ('mail.txt', \%params, \$mail_text); # E-Mail zusammenbauen aus Text, HTML und Anhang ------------------------------# my $Empfaenger = "spe\@spe-systemhaus.de"; my $msg = MIME::Lite->new(From => 'abc@spe-systemhaus.de', To => $Empfaenger, Subject => "Lieferschein $Liefernummer", Type => 'multipart/mixed'); # Innerer Rahmen als multipart/alternative ------------------------------------# my $alternative = $msg->attach (Type => 'multipart/alternative'); $alternative->attach (Type => 'text/plain', Data => $mail_text); $alternative->attach (Type => 'text/html', Data => $mail_html); $msg->attach (Type => 'application/pdf', Path => $Document, Filename => "Lieferschein $Liefernummer.pdf"); MIME::Lite->send('smtp', "mein.smtp.de", AuthUser=>'mein_benutzername', AuthPass=>'mein_passwort', SSL=>1, Port=>465, Debug=>0, Timeout=>60); $msg->send; unlink ($PCLFile); unlink ($CTLFile); unlink ($Document); exit 0;