Config postfix smarthost » Historie » Version 3
Jeremias Keihsler, 05.04.2024 10:48
1 | 1 | Jeremias Keihsler | h1. Config postfix smarthost |
---|---|---|---|
2 | |||
3 | 3 | Jeremias Keihsler | h2. smarthost with any smtp-server |
4 | |||
5 | have a look at: https://www.alldiscoveries.com/configuring-relayhost-smarthost-ubuntu-server-22-04-lts-with-gmail-or-another-email-server-via-postfix/ |
||
6 | |||
7 | 2 | Jeremias Keihsler | h2. smarthost with local mailcow-dockerized |
8 | |||
9 | 1 | Jeremias Keihsler | currently we are using Ubuntu only as a base for mailcow. |
10 | So things are a bit different here, see also: https://docs.mailcow.email/post_installation/firststeps-local_mta/ |
||
11 | |||
12 | 2 | Jeremias Keihsler | h3. install postfix and mail |
13 | 1 | Jeremias Keihsler | |
14 | <pre><code class="shell"> |
||
15 | sudo apt install mailutils |
||
16 | </code></pre> |
||
17 | |||
18 | 2 | Jeremias Keihsler | h3. configure postfix |
19 | 1 | Jeremias Keihsler | |
20 | <pre><code class="shell"> |
||
21 | sudo vim /etc/postfix/master.cf |
||
22 | </code></pre> |
||
23 | |||
24 | <pre> |
||
25 | #smtp inet n - - - - smtpd |
||
26 | </pre> |
||
27 | |||
28 | <pre><code class="shell"> |
||
29 | sudo vim /etc/postfix/main.cf |
||
30 | </code></pre> |
||
31 | |||
32 | <pre> |
||
33 | # as per https://docs.mailcow.email/post_installation/firststeps-local_mta/ |
||
34 | relayhost = 172.22.1.1 |
||
35 | mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 |
||
36 | inet_interfaces = loopback-only |
||
37 | relay_transport = relay |
||
38 | default_transport = smtp |
||
39 | </pre> |
||
40 | |||
41 | additionally we need to know the server and email-address as well as the password to use |
||
42 | <pre><code class="shell"> |
||
43 | vim /etc/postfix/sasl_passwd |
||
44 | </code></pre> |
||
45 | |||
46 | <pre> |
||
47 | mail.example.com:587 mailadr@example.com:password |
||
48 | </pre> |
||
49 | |||
50 | The above server hostname and port must exactly match the value for "relayhost" in /etc/postfix/main.cf. |
||
51 | |||
52 | Generate a postfix lookup table from the previous file |
||
53 | <pre><code class="shell"> |
||
54 | postmap hash:/etc/postfix/sasl_passwd |
||
55 | </code></pre> |
||
56 | |||
57 | Test the lookup table, if all is good then the following will return the specified username:password |
||
58 | <pre><code class="shell"> |
||
59 | postmap -q mail.example.com:587 /etc/postfix/sasl_passwd |
||
60 | </code></pre> |
||
61 | |||
62 | next is to bind the local username to the email-address. You may also have a look into @/etc/aliases@ and check who's mail are sent to whom. |
||
63 | <pre><code class="shell"> |
||
64 | vim /etc/postfix/canonical |
||
65 | </code></pre> |
||
66 | |||
67 | <pre> |
||
68 | root mailadr@example.com |
||
69 | </pre> |
||
70 | |||
71 | The above email-address must exactly match the email-address in sasl_passwd. |
||
72 | |||
73 | Generate a postfix lookup table from the previous file |
||
74 | <pre><code class="shell"> |
||
75 | postmap hash:/etc/postfix/canonical |
||
76 | </code></pre> |
||
77 | |||
78 | Make sure that sasl_passwd and sasl_passwd.db files are readable/writeable only by root |
||
79 | <pre><code class="shell"> |
||
80 | chmod 600 /etc/postfix/sasl_passwd |
||
81 | chmod 600 /etc/postfix/sasl_passwd.db |
||
82 | </code></pre> |
||
83 | |||
84 | Add postfix to be started at boot |
||
85 | <pre><code class="shell"> |
||
86 | systemctl enable postfix |
||
87 | </code></pre> |
||
88 | |||
89 | 2 | Jeremias Keihsler | h4. maybe necessary |
90 | 1 | Jeremias Keihsler | |
91 | <pre><code class="shell"> |
||
92 | sudo mkfifo /var/spool/postfix/public/pickup |
||
93 | </code></pre> |