5

My scenario is that I have an air gapped machine for keysigning. I was given some code that generates emails for individuals to receive their signed keys but I would like to keep this machine off any network. I set up Postfix on this machine to put all email into the hold queue. Now I'm trying to figure out a way to inject these emails onto my networked server with Postfix properly set up to deliver mail. I've tried moving the email into the hold directory and queueing them with sudo postsuper -r ALL. It says the messages were queued, but they never get delivered. Has anyone successfully accomplished this?

4 Answers 4

4

If anyone else has this issue, I ended up accomplishing my goal by using postcat to dump all the queued emails into separate files, copied those to the new server and injected them into Postfix using sendmail -t. The -t flag instructs sendmail to use the headers from the file instead of specifying the sender and recipient as command line arguments.

4

I was able to accomplish all this with a single command, and send the message directly to another server via ssh. I also edited the From field, setting it to the one from msg_id_in_queue (taken from enviromental variables, otherwise):

postcat -bhq <msg_id_in_queue> | ssh user@server2 "sendmail -t -f [email protected]"

This might be improved using regex to extract the From field directly from the original message, plus deleting the msg_id_in_queue thereafter, but for the use I needed, this was enough.

4

You can set in the transport file /etc/postfix/transport a line like this:

* smtp:[new_server_dns_or_ip]

Then do:

postmap /etc/postfix/transport

Then do postfix reload to load changes.

Then flush the queue with:

postqueue -f

If instead of setting * you set a domain name, only mails to this domain will be redirected to the new server.

2

I had a dead server which still had mails in /var/spool/postfix/{maildrop,defer,deferred}/. I was able to just copy the files into the right places on a working server. This is how:

  • Move disk containing /var from dead server to working server, and mount it. In this example, /var was a separate partition, and it's mounted at /mnt/old_var/

  • Set correct permissions on the files (in case UIDs are different):

chown -R postfix:postdrop /mnt/old_var/spool/postfix/maildrop
chown -R postfix:postfix  /mnt/old_var/spool/postfix/defer*
  • Move maildrop files

mv /mnt/old_var/spool/postfix/maildrop/* /var/spool/postfix/maildrop/

  • Move deferred files
cd /mnt/old_var/spool/postfix/
find defer -type f -printf "%P\n" \
| while read f; do
    for d in defer deferred; do
      mv -v $d/$f /var/spool/postfix/$d/$f
    done
done

or the same last command as a single line:

cd /mnt/old_var/spool/postfix/; find defer -type f -printf "%P\n" | while read f; do for d in defer deferred; do mv -v $d/$f /var/spool/postfix/$d/$f; done; done

You must log in to answer this question.

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