Email » History » Version 1
Gareth Eaton, 12/18/2024 06:40 PM
1 | 1 | Gareth Eaton | h1. Email |
---|---|---|---|
2 | |||
3 | Configuring SASL Password File and Postfix for Various SMTP Servers |
||
4 | |||
5 | The process of setting up the SASL password file and configuring Postfix to use an external SMTP server for email sending is adaptable for use with most SMTP servers, |
||
6 | |||
7 | Open the Terminal on your server where Postfix is installed. |
||
8 | |||
9 | While the core principles and steps remain the same, adjustments may be necessary to accommodate the specific requirements of different SMTP providers. |
||
10 | |||
11 | |||
12 | *Step 1: Create or Edit the SASL Password File:* |
||
13 | |||
14 | You need to create a file named sasl_passwd in the /etc/postfix/ directory. |
||
15 | This file will contain the SMTP server details and the credentials used for authentication. |
||
16 | Use a text editor to open or create this file. For example, using nano: |
||
17 | <pre> |
||
18 | sudo nano /etc/postfix/sasl_passwd |
||
19 | </pre> |
||
20 | |||
21 | Enter the SMTP Server and Credentials: |
||
22 | |||
23 | Inside the sasl_passwd file, you'll need to specify the SMTP server and your credentials in the following format: |
||
24 | |||
25 | <pre> |
||
26 | [smtp.gmail.com]:587 [email protected]:yourapppassword |
||
27 | </pre> |
||
28 | |||
29 | For Office 365: [smtp.office365.com]:587 |
||
30 | For Yahoo Mail: [smtp.mail.yahoo.com]:587 |
||
31 | |||
32 | Replace [email protected] with your actual mail address. |
||
33 | Replace yourapppassword with the app password you generated from your mail account. |
||
34 | Ensure you have enabled 2-step verification and generated an app password specifically for this use. |
||
35 | |||
36 | *Step 2: Secure the SASL Password File* |
||
37 | Set Appropriate Permissions: |
||
38 | |||
39 | It's important to secure this file since it contains sensitive information. |
||
40 | You should set the permissions so that only the root user can read and write to this file: |
||
41 | |||
42 | <pre> |
||
43 | sudo chmod 600 /etc/postfix/sasl_passwd |
||
44 | </pre> |
||
45 | |||
46 | Create a Hash Database File for Postfix: |
||
47 | |||
48 | Postfix does not use the sasl_passwd file directly. |
||
49 | Instead, it uses a hash database file that you need to generate from the sasl_passwd file: |
||
50 | |||
51 | <pre> |
||
52 | sudo postmap /etc/postfix/sasl_passwd |
||
53 | </pre> |
||
54 | |||
55 | This command creates a file named sasl_passwd.db in the same directory. |
||
56 | Postfix will use this hashed version for authentication. |
||
57 | |||
58 | *Step 3: Configure Postfix to Use the SASL Password File* |
||
59 | |||
60 | Edit the Postfix Configuration File: |
||
61 | |||
62 | Open the main Postfix configuration file, main.cf, located in /etc/postfix/: |
||
63 | <pre> |
||
64 | sudo nano /etc/postfix/main.cf |
||
65 | </pre> |
||
66 | |||
67 | Add or ensure these lines are present in the file: |
||
68 | makefile |
||
69 | |||
70 | |||
71 | <pre> |
||
72 | smtp_sasl_auth_enable = yes |
||
73 | smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd |
||
74 | smtp_sasl_security_options = noanonymous |
||
75 | smtp_use_tls = yes |
||
76 | smtp_tls_security_level = encrypt |
||
77 | smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt |
||
78 | </pre> |
||
79 | |||
80 | These settings enable SASL authentication, |
||
81 | specify the location of the SASL password map, |
||
82 | enforce the use of encryption, |
||
83 | and specify the CA certificates file for TLS. |
||
84 | |||
85 | *Step 4: Reload Postfix to Apply Changes* |
||
86 | After making all these changes, you need to reload Postfix to apply them: |
||
87 | <pre> |
||
88 | sudo systemctl reload postfix |
||
89 | </pre> |
||
90 | |||
91 | *Step 5: Test Email Sending* |
||
92 | Finally, test to ensure that emails can be sent using the configured SMTP server: |
||
93 | |||
94 | <pre> |
||
95 | echo "Test email from Postfix" | mail -s "Test Email" [email protected] |
||
96 | </pre> |
||
97 | |||
98 | Replace [email protected] with an actual email address where you can check the inbox to confirm receipt of the test email. |