I'd like to write emails now and have them go out at some specific time in the future, eg. when the office opens in the morning.

What would be a good way to do that ?

Most user agents don't support this feature. That makes sense to me, because you probably can't expect them to run around the clock.

Is there a server side feature for delayed sendinmg ? I run a Postfix mail server right now.

What is the Unix way of doing this ?

(I know KMail has this feature, but I'd like to avoid this particular application, because it drags along a huge amount of infrastructure.)

  • 3
    use a cron job – Fiximan Sep 7 '15 at 17:38
  • Thats probably a good option to do it once, but not really handy to use on a regular basis... – Gene Vincent Sep 7 '15 at 17:39
  • Why? cron is specifically designed for doing things regularly. – Fiximan Sep 7 '15 at 17:48
  • I think its inconvenient, because I'll have to create files wil the email text and add cron entries manually with the appropriate "mail recpt@example.com -r myemail@foo.com < mail12345.txt" command. Thats quite a step down from regular GUI user agents. – Gene Vincent Sep 7 '15 at 17:55
  • 2
    Depends. You can as well check where your e-mail client saves drafts and then use this file in the cron job. E.g. for my icedove (essentially thunderbird), it is saved in ./icedove/<profileID>/Mail/<addressID>/Drafts. You will then just have to evaluate this file with a script to export the essentials and pass them to mail. – Fiximan Sep 7 '15 at 18:01

If you are using postfix, there is a mechanism explained here, which I havent tried.

Reconfigure postfix by copying /etc/postfix/main.cf and adding lines:

defer_transports = hold
default_transport = hold

Beware, you may already have a default_transport. Swap your new file with the real main.cf and restart postfix and send your mails. They will be placed in the hold queue. To release the queue, restore the real main.cf, restart postfix and force the queue to release with

sudo service postfix restart
sudo mailq -q

Instead of the above, you can hold mail with a given header, for example if your mail program lets you add X- style headers, or if you want to match on a given Subject: junk of the day header string. Check that your postfix implements the regexp feature:

postconf -m|egrep 'regexp|pcre'

should output at least regexp. Create the file /etc/postfix/header_checks and place in it the regexp pattern of the header you want to match, followed by HOLD, eg:

/Subject: *junk of the day/ HOLD

Add the name of this map file to /etc/postfix/main.cf:

header_checks = regexp:/etc/postfix/header_checks

and restart postfix. Send a suitable mail and check with mailq that it is in the hold queue (a ! shows next to the queue id. To release and send all held mails:

sudo postsuper -H  ALL
sendmail -q
  • If I understand the feature correctly, it think it would hold all outgoung mails until disabled again, not individual mails. – Gene Vincent Sep 8 '15 at 2:38
  • I added an answer which matches a subject header, for example. – meuh Sep 8 '15 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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