summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfukachan <fukachan>2001-05-05 13:50:58 +0000
committerfukachan <fukachan>2001-05-05 13:50:58 +0000
commitca39a39b636b0bd2f51da9c351837f344b4d12c9 (patch)
tree7a0ef4584db8367cfd0ec61a331a33649bf9cd94
parentcca98990b34a8f8f5090b6900b8877ad2fdebf9d (diff)
downloadfml8-ca39a39b636b0bd2f51da9c351837f344b4d12c9.tar.gz
fml8-ca39a39b636b0bd2f51da9c351837f344b4d12c9.tar.bz2
fml8-ca39a39b636b0bd2f51da9c351837f344b4d12c9.zip
sendmail() utility which is a wrapper for Mail::Delivery
-rw-r--r--fml/lib/FML/Mailer.pm131
-rwxr-xr-xregress/message/send.pl34
2 files changed, 165 insertions, 0 deletions
diff --git a/fml/lib/FML/Mailer.pm b/fml/lib/FML/Mailer.pm
new file mode 100644
index 00000000..f3b0d159
--- /dev/null
+++ b/fml/lib/FML/Mailer.pm
@@ -0,0 +1,131 @@
+#-*- perl -*-
+#
+# Copyright (C) 2001 Ken'ichi Fukamachi
+# All rights reserved. This program is free software; you can
+# redistribute it and/or modify it under the same terms as Perl itself.
+#
+# $FML: __template.pm,v 1.5 2001/04/03 09:45:39 fukachan Exp $
+#
+
+package FML::Mailer;
+use strict;
+use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
+use Carp;
+use FML::Log qw(Log LogError);
+
+=head1 NAME
+
+FML::Mailer - Utilities to send mails
+
+=head1 SYNOPSIS
+
+ use FML::Mailer;
+ my $obj = new FML::Mailer;
+ $obj->send( {
+ sender => 'rudo@nuinui.net',
+ recipient => 'kenken@nuinui.net',
+ message => $message,
+ });
+
+where C<$message> is a C<Mail::Message> object to be sent.
+If you sent plural recipinets, you can pass the list of recipients by
+HASH ARRAY.
+
+ $obj->send( {
+ sender => 'rudo@nuinui.net',
+ recipients => [ 'kenken@nuinui.net', 'hitomi@nuinui.net' ],
+ message => $message,
+ });
+
+
+=head1 DESCRIPTION
+
+=head1 METHODS
+
+=head2 C<new()>
+
+usual constructor.
+
+=cut
+
+
+sub new
+{
+ my ($self) = @_;
+ my ($type) = ref($self) || $self;
+ my $me = {};
+ return bless $me, $type;
+}
+
+
+=head2 C<send($args)>
+
+method to send the given C<message>.
+
+=cut
+
+sub send
+{
+ my ($self, $args) = @_;
+ my ($config, $maintainer, $fp, $sfp) = ();
+
+ # $curproc is given in usual fml processes.
+ # but not in other programs.
+ if (defined $args->{ curproc }) {
+ $config = $args->{ curproc }->{ config } || undef;
+ $maintainer = $config->{ maintainer };
+
+ $fp = sub { Log(@_);}; # pointer to the log function
+ $sfp = sub { my ($s) = @_; print $s; print "\n" if $s !~ /\n$/o;};
+ }
+
+ # Mail::Message which is sent
+ my $message = $args->{ message } || undef;
+
+ # who is sender
+ my $sender = $args->{ sender } || $maintainer;
+
+ # recipient(s): expected to be given as string or HASH ARRAY
+ my $recipient = $args->{ recipient } || undef;
+ my $recipients = $args->{ recipients } || [ $recipient ] || undef;
+
+
+ ### main ###
+ use Mail::Delivery;
+ my $service = new Mail::Delivery {
+ log_function => $fp,
+ smtp_log_function => $sfp,
+ };
+ if ($service->error) { LogError($service->error); return 0;}
+
+ $service->deliver({
+ 'smtp_sender' => $sender,
+ 'recipient_array' => $recipients,
+ 'message' => $message,
+ });
+ if ($service->error) { LogError($service->error); return 0;}
+
+ return 1;
+}
+
+
+=head1 AUTHOR
+
+Ken'ichi Fukamachi
+
+=head1 COPYRIGHT
+
+Copyright (C) 2001 Ken'ichi Fukamachi
+
+All rights reserved. This program is free software; you can
+redistribute it and/or modify it under the same terms as Perl itself.
+
+=head1 HISTORY
+
+FML::Mailer appeared in fml5 mailing list driver package.
+See C<http://www.fml.org/> for more details.
+
+=cut
+
+
+1;
diff --git a/regress/message/send.pl b/regress/message/send.pl
new file mode 100755
index 00000000..155b415b
--- /dev/null
+++ b/regress/message/send.pl
@@ -0,0 +1,34 @@
+#!/usr/local/bin/perl
+#-*- perl -*-
+#
+# Copyright (C) 2001 Ken'ichi Fukamachi
+# All rights reserved. This program is free software; you can
+# redistribute it and/or modify it under the same terms as Perl itself.
+#
+# $FML: basic_io.pl,v 1.4 2001/04/13 04:34:07 fukachan Exp $
+#
+
+use strict;
+use Carp;
+use lib qw(../../cpan/lib ../../fml/lib);
+use Mail::Message;
+use FileHandle;
+
+my $sender = 'elena-admin@sapporo.iij.ad.jp';
+my $rcpt = 'fukachan@sapporo.iij.ad.jp';
+my $array = [ $rcpt ];
+
+for my $file (@ARGV) {
+ my $fh = new FileHandle $file;
+ my $msg = Mail::Message->parse( { fd => $fh } );
+
+ use FML::Mailer;
+ my $obj = new FML::Mailer;
+ $obj->send( {
+ sender => $sender,
+ recipient => $rcpt,
+ message => $msg,
+ });
+}
+
+exit 0;