If you have a mail receiver container which requires customised Postfix configuration, this is the topic for you. Herein are described the steps required to set Postfix main.cf configuration variables to whatever your heart desires.
Postfix configuration variables can be set via the container environment. Any environment variable starting with POSTCONF_ will set a Postfix configuration variable named for the rest of the environment variable to the value of the environment variable. For example, if you set the environment variable POSTCONF_always_bcc to bob@example.com, then Postfix will be configured with always_bcc = bob@example.com, which will send a copy of all incoming mail to Bob. Poor Bob.
Procedure
-
Figure out what configuration variables you want to set, and what values to set them to. This may be done by reading the fine manual, or through recommendations in other Discourse documentation, or otherwise.
-
Connect to your Discourse server via SSH, grab some
rootprivileges, and head over to where all thediscourse-dockerconfiguration lives:ssh ubuntu@192.0.2.42 sudo -i cd /var/discourse -
Open up
containers/mail-receiver.ymlin your text editor of choice, and swing down to theenv:section of the file. Somewhere in there, add entries for the variables you want to add, being careful to not modify anything else, and maintaining appropriate indenting. For example, if we were adding ouralways_bccsetting, the file might look a bit like this:env: LANG: en_US.UTF-8 MAIL_DOMAIN: discourse.example.com DISCOURSE_BASE_URL: 'https://discourse.example.com' DISCOURSE_API_KEY: abcdefghijklmnop DISCOURSE_API_USERNAME: system POSTCONF_always_bcc: 'bob@example.com'Once you’re happy with what you’ve added, save and exit your editor.
-
To load the configuration, you simply have to restart the
mail-receivercontainer (arebuildis not required):./launcher restart mail-receiverAfter a brief spasm, the container should be running again.
-
Test your changes. Ensure both that what you wanted to have happen has, indeed, happened, and also that nothing you didn’t expect to change hasn’t.
Addendum: adding files to the mail-receiver container
Many Postfix configuration parameters require access to “database files”, which provide key/value information which Postfix uses to make decisions about what do with mail. If you see that a configuration parameter accepts a filename that looks like hash:/some/file, you’ve found a use for database files.
The thing is, Postfix running inside the container needs to be able to get at those files while it’s running, which means you need to either copy those files into the container, or (preferably) put those files into a directory on the host, and then mount that directory as a volume inside the container. These instructions describe the second method.
Once you have completed this procedure, any file you place into /var/discourse/shared/mail-receiver/etc will immediately become visible at /etc/postfix/shared inside the container, and any changes you make to those files will be immediately visible to Postfix.
Here’s how to make it happen.
-
If you’re not still logged in as root to your Discourse server, do so again:
ssh ubuntu@192.0.2.42 sudo -i cd /var/discourse -
Open up
containers/mail-receiver.ymlin your text editor of choice, and this time head for thevolume:section. Underneath the existing definition for the/var/spool/postfixdirectory, add another one, so that yourvolumesection looks like this:volumes: - volume: host: /var/discourse/shared/mail-receiver/postfix-spool guest: /var/spool/postfix - volume: host: /var/discourse/shared/mail-receiver/etc guest: /etc/postfix/sharedSave/exit your editor.
-
To attach the new volume, you simply have to restart the
mail-receivercontainer (arebuildis not required):./launcher restart mail-receiver
All done!
