Tobias Weisserth: Formmail mit blat.exe statt sendmail

Beitrag lesen

Hallo Sven,

erstmal Dankeschön für die erste Antwort. Ich habe die das Readme von Blat aufgetrieben und da heisst es:

syntax:
  Blat <filename> -t <recipient> [optional switches (see below)]
  Blat -install <server addr> <sender's addr> [<try>[<port>[<profile>]]] [-q]
  Blat -profile [-delete | "<default>"] [profile1] [profileN] [-q]
  Blat -h [-q]

-install <server addr> <sender's addr> [<try n times> [<port> [<profile>]]]
     : set's SMTP server, sender, number of tries and port for profile
       (<try n times> and <port> may be replaced by '-').

<filename>     : file with the message body ('-' for console input, end with ^Z)
-t <recipient> : recipient list (comma separated)
-s <subj>      : subject line
-f <sender>    : overrides the default sender address (must be known to server)
-i <addr>      : a 'From:' address, not necessarily known to the SMTP server.
-c <recipient> : carbon copy recipient list (comma separated)
-b <recipient> : blind carbon copy recipient list (comma separated)
-o <organization>: Organization field
-x <X-Header: detail>: Custom 'X-' header.  eg: -x "X-INFO: Blat is Great!"
-r             : Request return receipt.
-d             : Request disposition notification.
-h             : displays this help.
-q             : supresses *all* output.
-debug         : Echoes server communications to screen (disables '-q').
-noh           : prevent X-Mailer header from showing homepage of blat
-noh2          : prevent X-Mailer header entirely
-p <profile>   : send with SMTP server, user and port defined in <profile>.
-server <addr> : Specify SMTP server to be used. (optionally, addr:port)
-port <port>   : port to be used on the server, defaults to SMTP (25)
-hostname <hst>: select the hostname used to send the message
-mime          : MIME Quoted-Printable Content-Transfer-Encoding.
-uuencode      : Send (binary) file UUEncoded
-base64        : Send (binary) file using base64 (binary Mime)
-try <n times> : how many time blat should try to send. from '1' to 'INFINITE'
-attach <file> : attach binary file to message (may be repeated)
-attacht <file>: attach text file to message (may be repeated)
-ti <n>        : Set timeout to 'n' seconds.

Note that if the '-i' option is used, <sender> is included in 'Reply-to:'
and 'Sender:' fields in the header of the message.

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

Interessant ist der Teil mit dem <filename>. Wenn ich das richtig verstehe, kann ich also an STDIN über einen Dateistream Daten an Blat schicken. Wie teile ich ihm aber mit, dass er alles hat und senden soll?

So sieht der entsprechende Teil für sendmail aus:

open(MAIL,"|$mailprog -t");
print MAIL "To: $Config{'recipient'}\n";
...
close (MAIL);

Schluckt Blat das genauso? Wie muss ich das mit dem ^Z verstehen? Dann galube ich, dass ich auch noch die Parameter etwas anders benutzen muss.

Meinst Du, das könnte funktionieren? Einziges Problem dürfte sein, dass Blat vielleicht die Steuerzeichen nicht interpretiert, oder? Wenn nämlich die Formatierung verloren geht, war der Sinn und Zweck der Aktion umsonst.

sub send_to_blat {

# Benötigte Variablen lokal zur Verfügung stellen                          #
      local($print_config,$key,$sort_order,$sorted_field,$env_report);

# Email Subject bestimmen
   $betreff = '';
      if ($Config{'subject'}) { $betreff = $Config{'subject'} }
      else                    { $betreff = WWW Form Submission }

# Adresse bestimmen
  $address = $Config{'recipient'};

# Messageinhalt bestimmen
  # Variable initialisieren, hier soll der komplette Textkörper hineingeschrieben werden
  $message = 'Anbei die Resultate der Befragung. Sie wurden abgeschickt durch:\n' . '$Config{'realname'} ($Config{'email'}) on $date\n';

# Prüft die Option print_config und handelt entsprechend
  if (@Print_Config) {
     foreach $print_config (@Print_Config) {
          if ($Config{$print_config}) {
          $message .= '$print_config: $Config{$print_config}\n\n';
       }
     }
  }

# Alphabetisch sortieren, falls verlangt                             #
     if ($Config{'sort'} eq 'alphabetic') {
           foreach $field (sort keys %Form) {

# If the field has a value or the print blank fields option      #
            # is turned on, print out the form field and value.              #
            if ($Config{'print_blank_fields'} || $Form{$field} ||
                $Form{$field} eq '0') {
                $message .= '$field: $Form{$field}\n\n';
            }
         }
     }

# Felder nach angegebener Reihenfolge sortieren, falls verlangt      #
  elsif ($Config{'sort'} =~ /^order:.*,.*/) {

# Remove extraneous line breaks and spaces, remove the order:  #
     # directive and split the sort fields into an array.           #
           $Config{'sort'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
           $Config{'sort'} =~ s/(\s+)?\n+(\s+)?//g;
           $Config{'sort'} =~ s/order://;
           @sorted_fields = split(/,/, $Config{'sort'});

# For each sorted field, if it has a value or the print blank  #
           # fields option is turned on print the form field and value.   #
           foreach $sorted_field (@sorted_fields) {
                  if ($Config{'print_blank_fields'} || $Form{$sorted_field} || $Form{$sorted_field} eq '0') {
                   $message .= '$sorted_field: $Form{$sorted_field}\n\n';
                }
           }
       }

# Ansonsten in der angegeben Reihenfolge verschicken      #
       else {

# For each form field, if it has a value or the print blank          #
        # fields option is turned on print the form field and value.         #
        foreach $field (@Field_Order) {
            if ($Config{'print_blank_fields'} || $Form{$field} || $Form{$field} eq '0') {
                $message .= '$field: $Form{$field}\n\n';
            }
        }
    }

# System Umgebungsvariablen mit in die Nachricht einpacken                 #
      foreach $env_report (@Env_Report) {
        if ($ENV{$env_report}) {
            $message .= '$env_report: $ENV{$env_report}\n';
        }
      }

# Zusammenstellen der Kommandozeile für späteren Systemaufruf
   $commandline = $mailprog;
   $commandline .= $message;
   $commandline .= "-s "$betreff" " if $betreff;
   $commandline .= "-t "$recipients" " if $recipients;
   # $commandline .= "-f $config{'email'} " if $config{'email'};

# Senden der Email
   system($commandline);

Dummerweise kann ich nichts ausprobieren, bis das Skript live geht, ich habe keinen Zugang zum Server.

Gruß,
Tobias