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