Peter Makholm
and 1 contributors

NAME

Mail::Postfix::Postdrop - Inject mails to a Postfix maildrop directory

SYNOPSIS

  # Functional interface
  use Mail::PostFix::Postdrop 'inject';

  inject $message, Sender     => 'alice@example.net',
                   Recipients => [ qw(bob@example.com carol@example.net) ];

  
  # OOish interface

  my $postdrop = Mail::Postfix::Postdrop->new( $message );

  $postdrop->build;    # Build the content of the queue file 
  $postdrop->write;    # Write it to the maildrop queue
  $postdrop->release;  # Let pickup(8) process the queue file
  $postdrop->notify;   # Notify pickup(8) about new files (Optional)

  # Or through postdrop(1)

  my $postdrop = Mail::Postfix::Postdrop->new( $message, Timestamp => undef );
  open my $fh, "|-", "/usr/sbin/postdrop"
      or die "...";
  print $fh $postdrop->build
      or die "...";
  close $fh
      or die "...";

DESCRIPTION

Bone::Mail::Postfix::Postdrop implements parts of postfix's postdrop(1) utility. Using the functionel interface you can inject messages directly into the maildrop queu and using the OOish interface you can control parts of the process.

The main use case is writing the mail to a queue where postfix will take the responsability to deliver the mail without letting postfix handle the mail immediately. This can be used for sending mails in transactions.

FUNCTIONS

inject

  inject $message, %overrides;

Given a message, either as a Email::Abstract object or as something Email::Abstract->new() will process (like a string), this function will inject the mail into Postfix's maildrop queue. If not overridden sender and recipients will be extracted from the message. (Need to be in group 'postdrop')

The following overrides is supported:

Sender (string)

Default: content of the Sender or From header

Recipients (arrayref)

Default: content of To, CC, and BCc headers.

Attr (hashref)

Attributes to further posfix processing. Default:

  { rewrite_context => 'local' }

Timestamp (integer or undef)

Timestamp to stamp the queue file with (posix timestamp). The default is the current time. If timestamp is explicitly set to undef no timestamp will be created. This is needed for sending through postdrop(1).

METHODS

The following methods is supported:

new

Takes the same arguments as the inject function without injecting the mail immediately.

build

Builds the queue content. If you change the content you'll have to call build again or you will inject old mail. Returns a string containing the queue content.

write

Write the content to a maildrop file. Returns a false value on failure and sets $! arcordingly. (Need to be in group 'postdrop')

release

Releases the queue file so pickup(8) will indeed pick it up next time it scans the maildrop queue. (Need to be in group 'postdrop')

notify

Notifies pickup(8) that new mail has been placed in the maildrop queue. By calling this function you mail should be processed immediately otherwise pickup should automatically scan the queue each minute.

check

Checks if the queue file still exists. Notice that notify is nonblocking and on a loaded system it may take a while for the mail to be processed. There is also a minor chance that some other mail with the same name might be generated in the mean time.

BUGS AND INCONVENIENCES

Some of the methods needs to run as the postdrop group. If you can't run you script in this group you have to pipe through postdrop.

Please report any bugs or feature requests to bug-mail-postfix-postdrop at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Mail-Postfix-Postdrop. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

TODO

It would be nice to restore the ability from Qpsmtpd::Postfix to talk directly to the cleanup(8)-daemon.

AUTHOR

Peter Makholm, <makholm at one.com>

COPYRIGHT & LICENSE

Copyright 2008 One.com, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

ACKNOWLEDGEMENTS

Partly based on Qpsmptd::Postfix by Ask Bjoern Hansen, Develooper LCC

# vim:sw=2