Peter Makholm
and 1 contributors


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


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

  inject $message, Sender     => '',
                   Recipients => [ qw( ];

  # 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 "...";


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.



  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).


The following methods is supported:


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


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 the content to a maildrop file. Returns a false value on failure and sets $! arcordingly. (Need to be in group 'postdrop')


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')


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.


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.


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, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


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


Peter Makholm, <makholm at>


Copyright 2008, all rights reserved.

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


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

# vim:sw=2