Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm wondering if it's possible to create mail packages and put them into the postfix queue simply by writing files to the hard drive.

Currently I have a script which uses a socket connection to dump the data in, but if I could write it directly to the hard drive this would speed things up considerably. Is this possible?

share|improve this question
add comment

3 Answers

Yes, using the maildrop queue: http://www.postfix.org/MAILDROP_README.html#maildrop_queue

Postfix queues are just directories in the filesystem; queued items are inodes that move from one directory (queue) to another; the file uses a custom binaryish format containing all metadata needed to process it.

There exists a perl module Mail::Postfix::Postdrop that sticks mail in the maildrop directory.

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

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

You may be able to use postdrop itself (which is how the 'sendmail' command injects mail into the queue):

 The  postdrop(1)  command  creates  a file in the maildrop
 directory and copies its standard input to the file.

I havent' done either; let us know if you have any luck with this.

share|improve this answer
add comment

Once upon a time, one could do exactly that with Postfix. After all, the maildrop is nothing more than a directory that files are written to. The trouble is that one can play all sorts of tricks with a world-writable maildrop directory. (This was long since known even at the time that Postfix was first written.) So on a properly set up system, you won't be able to just write out files.

This almost certainly isn't your bottleneck in the first place. This is, after all, electronic mail that we are talking about, where there's a big thing called "the Internet" that is often the slowest part of the system. I strongly suspect that you haven't analyzed your bottlenecks to see what and where they are, and that your idea that writing directly to a spool file will "speed things up considerably" is based upon hope rather than measurement.

It's fairly easy to eliminate any of the delays in an SMTP Submission dialogue with SMTP pipelining. And, as mentioned in another answer, using Postfix's sendmail utility — which is little more than a wrapper around postdrop in this case — is also an option. But saving a second in message submission is likely to be lost in the noise if your real bottleneck is, for example, a dial-up Internet connection.

share|improve this answer
add comment

You're not supposed to cram stiff into the queue like that, however, you can use the command line mail tools, like:

sendmail -i [recipient@address] < [file]

which I think should keep everything server side until postfix attempts to deliver.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.