> For the complete documentation index, see [llms.txt](https://docs.glesys.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.glesys.com/products/compute/guides-for-server-management/sending-email-from-your-server-using-postfix.md).

# Sending email from your server using Postfix

***

When you need to send emails from your virtual machine or dedicated server, you’ll need some kind of SMTP server software. At Glesys, we typically use and recommend **Postfix**.

## Installation and configuration of Postfix

First, create a DNS record for your server, for example, `smtp.mydomain.com`.

Then, install Postfix using these commands (in Debian or Ubuntu):

{% code title="Command" %}

```
sudo apt-get update
sudo apt-get install postfix
```

{% endcode %}

When the installation runs, you’ll be asked what type of configuration to use for Postfix. Choose **Internet Site**.

After the installation is completed on your server, there are still some configuration steps to perform. This is especially important to reduce the risk of your email being marked as spam.

Start by changing the values for `myorigin`, `myhostname`, and `mydestination` in the file `/etc/postfix/main.cf`:

{% code title="Lines to modify in /etc/postfix/main.cf" %}

```
myhostname = smtp.mydomain.com
myorigin = smtp.mydomain.com
mydestination = localhost
```

{% endcode %}

The directives `myorigin` and `myhostname` specifies the domain that the mail server claims the email originates from.

Some mail programs use the hostname in `/etc/mailname` as the sender when sending outbound email. To make sure your emails don't bounce, set the hostname in `/etc/mailname` to the same value as `myhostname` and `myorigin` above, in this example, `smtp.mydomain.com`.

After you have made the above changes, restart Postfix with `sudo systemctl restart postfix`.

## PTR record

It’s important to set a correct PTR record for the IP address your server uses. You can do this in our control panel under **Networking → IP Addresses**.

The PTR record’s value should be your server’s hostname, e.g. `smtp.mydomain.com.`

**Note** the trailing `.` after the domain name.

Some email services require the domain to have an SPF record. This record lists the IP addresses that are permitted to send mail on behalf of the domain, helping to prevent spammers from hijacking the domain and sending bulk mail.

You can also set this up in our control panel under **DNS**.

Create a TXT‑type record containing:

{% code title="TXT record" %}

```
v=spf1 ip4:SERVERNS-IPv4-ADRESS ip6:SERVERNS-IPv6-ADRESS -all
```

{% endcode %}

## Logging and troubleshooting

To make troubleshooting a bit easier, you can add the following line at the end of `/etc/postfix/main.cf`:

{% code title="End of /etc/postfix/main.cf" %}

```
maillog_file = /var/log/mail.log
```

{% endcode %}

Then restart Postfix with `sudo systemctl restart postfix`. You can then see all the emails flowing in and out of the server in the log file `/var/log/mail.log`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.glesys.com/products/compute/guides-for-server-management/sending-email-from-your-server-using-postfix.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.
