2

I'm wondering if it's possible to create mail messages 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?

3 Answers 3

4

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.

1
  • Dead simple, works like a charm! I would alter the command to: sendmail -i -f [sender@address] [recipient@address] < [file]
    – Michael
    Dec 6, 2019 at 19:28
3

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     => '[email protected]',
                   Recipients => [ qw([email protected] [email protected]) ];

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.

2

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .