n.d. parker: Formmail mit blat.exe statt sendmail

Beitrag lesen

Moin Tobias,

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]

ich stand vor einer Weile vor dem selben Problem. Dabei ist folgendes Perlmodul herausgekommen:

package Blat;

################################################################################
#                                                                              #

File:        Blat.pm

#                                                                              #

Authors:     Andre Malo       nd@o3media.de, 2001-04-01

#                                                                              #

Description: send email using blat for windows

#                                                                              #

Copyright:   This package is free software; you can redistribute it

#              and/or modify it under the same terms as Perl itself.           #
#                                                                              #
################################################################################

use strict;
use vars qw(
  @EXPORT
  @ISA
);

################################################################################

Export

require Exporter;
@ISA = qw(Exporter);

@EXPORT = qw(
  send_blat
);

get_list ()

private sub

sub get_list ($) {
  my $list = shift;

return $list if (defined $list and not ref $list and length $list);

return join (', ',@$list) if (ref $list);

'';
}

send_blat ()

send email using blat for windows

Params: hashref {

#           to      => To  (string oder arrayref)
#           cc      => Cc  (string oder arrayref)
#           bcc     => Bcc (string oder arrayref)
#           subject => Subject
#           from    => From
#           reply   => Reply-To
#           body    => Mail Body
#         }

Return: success code (boolean)

Example:

#   send_blat ({
#     to      => 'mymother@herdomain.com',
#     cc      => [other@otherdomain.com', 'mybrother@hisdomain.com'],
#     subject => 'Hey, I found a nice module!',
#     from    => 'me@mydomain.com',
#     body    => "Hi!\nI found this very nice package Blat.pm.\n\n Regards - me. ;-))"
#   }) or die "could not send mail.";

sub send_blat {
  my $param = shift;

my $to = {
   -to  => get_list($param -> {to}  || ''),
   -cc  => get_list($param -> {cc}  || ''),
   -bcc => get_list($param -> {bcc} || '')
  };

my $subject = $param -> {subject};
  my $from    = $param -> {from};

for ($subject, $from) {
    $$_ =~ s/"/\"/g;
    $$_ =~ y/\n/ /s;
  }

my $body = $param -> {body};
  $body =~ s/^.$/. /gm;

my $reply='';
  if (defined $param->{reply} and length $param->{reply}) {
    $reply = $param->{reply};
    $reply =~ s/"/\"/g;
    $reply =~ y/\n/ /s;
    $reply = qq[-replyto "$reply" ];
  }

my $command = '| blat - -q -mime -noh2 -f "'.$from.'" -s "'.$subject.'" '.$reply
  #                     ^  ^   ^     ^
  #                     |  |   |     |
  #                     |  |   |     -- no X-Mailer Header   #                     |  |   -------- encode Quoted Printable
  #                     |  ------------ quiet mode (no output to STDOUT)   #                     --------------- mail body from STDIN
  #
    . join ' ' => map {
      my $ret = $to -> {$_};
      if (defined ($ret) and length ($ret)) {
        $ret =~ s/"/\"/g;
        $ret =~ y/\n/ /s;
        $ret =~ s/[1]*://;
        $ret = qq[$_ "$ret"]
      }
      $ret || ();
    } keys %$to;

open MAIL, $command or return;
  print MAIL $body or return;
  close MAIL and return 1;

# anything failed
  #
  return;
}

keep 'require' happy

1;

end of Blat

Verbesserungsvorschlaege erwuenscht ;-)

HTH &

Viele Gruesse,

n.d.p.


  1. ^: ↩︎