# How to install Postfix on Ubuntu

Want to send emails from your applications? Postfix is a reliable and secure mail transfer agent (MTA). This guide sets up a basic, secure outbound mail server.

***

### Requirements

* Linux [VPS](https://ititanhosting.com/vps) (Ubuntu 20.04+ recommended)
* [Domain name](https://ititanhosting.com/) (DNS access required)
* Open ports: 25, 587

***

### Step 1: Update system

```bash
sudo apt update
```

(Optional)

```bash
sudo apt upgrade -y
```

***

### Step 2: Install Postfix

```bash
sudo apt install postfix mailutils -y
```

Choose:

* **Internet Site**
* Domain: `example.com`

***

### Step 3: Basic configuration

```bash
sudo nano /etc/postfix/main.cf
```

Minimal config:

```
myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain

inet_interfaces = all
inet_protocols = ipv4

mydestination = $myhostname, localhost.$mydomain, localhost

mynetworks = 127.0.0.0/8
relay_domains =
```

***

### Step 4: Start Postfix

```bash
sudo systemctl restart postfix
sudo systemctl enable postfix
```

***

### Step 5: Test sending

```bash
echo "Test email" | mail -s "Test" your@email.com
```

Check logs:

```bash
sudo tail -f /var/log/mail.log
```

***

### Step 6: DNS setup (IMPORTANT)

Add:

* **MX** → mail.example.com
* **A** → mail.example.com → your IP

SPF:

```
v=spf1 mx ip4:YOUR_IP ~all
```

***

### Step 7: Enable authentication (basic)

```bash
sudo apt install libsasl2-modules sasl2-bin -y
```

***

### Common issues

#### Emails go to spam

* Missing SPF
* No reverse DNS (PTR)
* No DKIM

***

### Done 🎉

Postfix is ready to send emails.
