6

When using combination of Postfix/Dovecot, is there a way to tell smtp server (Postfix) not to store mails on disk but hold/add them to queue until "maintenance finished"?

Useful for disk upgrades, volume extensions, chkdisk etc.

Alex
  • 1,828
  • 4
  • 31
  • 52

3 Answers3

14

Use this to stop (pause) and start delivery of outgoing mail again:

sudo postconf -e defer_transports=smtp; sudo postfix reload
sudo postconf -e defer_transports=; sudo postfix reload; sudo postfix flush

This should be applicable to other transports as well.

Source: nixtips.net

bjoster
  • 4,805
  • 5
  • 25
  • 33
trogper
  • 241
  • 2
  • 4
3

Just shut down postfix. Any legit sending server will queue your mail and retry after a time delay if it is not able to contact your server. As long as your maintenance is short, say under 6 hours, your chances of losing mail are very small.

EEAA
  • 109,363
  • 18
  • 175
  • 245
  • 3
    This could be a good answer but then what to do with internal users who connect to the smtp for outgoing mail? – Alex Dec 21 '12 at 05:54
  • @Alex During maintenance? – Michael Hampton Dec 21 '12 at 18:20
  • 1
    @Alex - I agree with Michael here. If you only have a single server, you're clearly not in a high-availability environment to start with, so just take things down during a published maintenance period. This is fairly standard practice, and is typically well-received by users as long as you communicate with them about it. – EEAA Dec 21 '12 at 19:46
  • The nasty corner case involves things like [ActionMailer](https://guides.rubyonrails.org/action_mailer_basics.html) that need Postfix and send mail that isn't from local users. And really, why should a "forgot my password?" form have its own mail queue? – arnt Jul 12 '19 at 09:11
2

I don't believe so; the incoming queue is on disk. Perhaps you could temporarily move the queue to a ramdisk mount?

mkdir /mnt/pframqueue
mount -t tmpfs -o size=512M tmpfs /mnt/pframqueue
service postfix stop
mv /var/spool/postfix/* /mnt/pframqueue/
<<<adjust 'queue_directory' in main.cf to /mnt/pframqueue>>>
service postfix start

Do the opposite once you're done.

IMHO that's more trouble than it's worth, especially if something goes screwy in the mv

fukawi2
  • 5,396
  • 3
  • 32
  • 51