# 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ititanhosting.ro/docs/english/vps/linux/how-to-install-postfix-on-ubuntu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
