summaryrefslogtreecommitdiff
path: root/README.md
blob: 0b23ea84b4ea709f1f698231673243e456b54b48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Email server setup script

I wrote this script during the gruelling process of installing and setting up
an email server.  It perfectly reproduces my successful steps to ensure the
same setup time and time again.

I've linked this file on Github to a shorter, more memorable address on my
website so you can get it on your machine with this short command:

```
curl -LO lukesmith.xyz/emailwiz.sh
```

When prompted by a dialog menu at the beginning, select "Internet Site", then
give your full domain without any subdomain, i.e. `lukesmith.xyz`.

Read this readme and peruse the script's comments before running it.  Expect it
to fail and you have to do bug testing and you will be very happy when it
actually works perfectly.

## This script installs

- **Postfix** to send mail.
- **Dovecot** to receive mail.
- Config files that unique the two above securely with native log-ins.
- **Spamassassin** to prevent spam and allow you to make custom filters.
- **OpenDKIM** to validate you so you can send to Gmail and other big sites.

## This script does _not_

- use a SQL database or anything like that.
- set up a graphical interface for mail like Roundcube or Squirrel Mail. If you
  want that, you'll have to install it yourself. I just use
  [isync/msmtp/mutt-wizard](https://github.com/lukesmithxyz/mutt-wizard) to
  have an offline mirror of my email setup and I recommend the same. There are
  other ways of doing it though, like Thunderbird, etc.

## Requirements

1. A **Debian or Ubuntu server**. I've tested this on a
   [Vultr](https://www.vultr.com/?ref=8384069-6G) Debian server and one running
   Ubuntu and their setup works, but I suspect other VPS hosts will have
   similar/possibly identical default settings which will let you run this on
   them. Note that the affiliate link there to Vultr gives you a $100 credit
   for the first month to play around.
2. **A Let's Encrypt SSL certificate for your site's `mail.` subdomain**.
   Create a nginx/apache site at `mail.<yourdomain.com>` and get a certificate
   for it with Let's Encrypt's [Certbot](https://certbot.eff.org/).
3. You need two little DNS records set on your domain registrar's site/DNS
   server: (1) an **MX record** pointing to your own main domain/IP and (2) a
   **CNAME record** for your `mail.` subdomain.
4. `apt purge` all your previous (failed) attempts to install and configure a
   mailserver. Get rid of _all_ your system settings for Postfix, Dovecot,
   OpenDKIM and everything else. This script builds off of a fresh install.
5. Some VPS providers block port 25 (used to send mail). You may need to
   request that this port be opened to send mail successfully. Although I have
   never had to do this on a Vultr VPS, others have had this issue so if you
   cannot send, contact your VPS provider.

## Post-install requirement!

- After the script runs, you'll have to add two *additional DNS TXT records*
  which involves the OpenDKIM key that it generates during the script.

## Making new users/mail accounts

Let's say we want to add a user Billy and let him receive mail, run this:

```
useradd -m -G mail billy
passwd billy
```

Any user added to the `mail` group will be able to receive mail. Suppose a user
Cassie already exists and we want to let her receive mail to. Just run:

```
usermod -a -G mail cassie
```

A user's mail will appear in `~/.Mail/`. I you want to see your mail while
ssh'd in the server, you could just install mutt, add `set spoolfile="+Inbox"`
to your `~/.muttrc` and use mutt to view and reply to mail. You'll probably
want to log in remotely though:

## Logging in from Thunderbird or mutt (and others) remotely

Let's say you want to access your mail with Thunderbird or mutt or another
email program. For my domain, the server information will be as follows:

- SMTP server: `mail.lukesmith.xyz`
- SMTP port: 587
- IMAP server: `mail.lukesmith.xyz`
- IMAP port: 993
- Username `luke` (I.e. *not* `luke@lukesmith.xyz`)

The last point is important. Many email systems use a full email address on
login. Since we just simply use local PAM logins, only the user's name is used
(this makes a difference if you're using my
[mutt-wizard](https://github.com/lukesmithxyz/mutt-wizard), etc.).

## Tweaking things

You're a big boy now if you have your own mail server!

You can tweak Postfix (sending mail

## Benefited from this?

If this script or documentation has saved you some frustration, you can donate
to support me at [lukesmith.xyz/donate](https://lukesmith.xyz/donate.html).