2019-05-27 20:15:26 +00:00
|
|
|
# Email server setup script
|
|
|
|
|
2020-11-14 19:18:50 +00:00
|
|
|
I wrote this script during the grueling process of installing and setting up
|
2020-12-07 02:08:30 +00:00
|
|
|
an email server. It perfectly reproduces my successful steps to ensure the
|
|
|
|
same setup time and time again, now with many improvements.
|
|
|
|
|
|
|
|
I'm glad to say that dozens, hundreds of people have now used it and there is a
|
|
|
|
sizeable network of people with email servers thanks to this script.
|
2019-05-27 20:15:26 +00:00
|
|
|
|
2020-06-20 19:43:27 +00:00
|
|
|
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:
|
2019-05-27 20:15:26 +00:00
|
|
|
|
2020-09-27 10:47:39 +00:00
|
|
|
```sh
|
2019-05-27 23:33:08 +00:00
|
|
|
curl -LO lukesmith.xyz/emailwiz.sh
|
2019-05-27 20:15:26 +00:00
|
|
|
```
|
|
|
|
|
2020-06-20 19:43:27 +00:00
|
|
|
When prompted by a dialog menu at the beginning, select "Internet Site", then
|
|
|
|
give your full domain without any subdomain, i.e. `lukesmith.xyz`.
|
2019-05-27 23:24:23 +00:00
|
|
|
|
2020-06-20 19:43:27 +00:00
|
|
|
## This script installs
|
2019-05-27 20:15:26 +00:00
|
|
|
|
2020-06-30 09:06:23 +00:00
|
|
|
- **Postfix** to send and receive mail.
|
2020-11-14 19:18:50 +00:00
|
|
|
- **Dovecot** to get mail to your email client (mutt, Thunderbird, etc.).
|
2020-09-27 10:47:39 +00:00
|
|
|
- Config files that link the two above securely with native log-ins.
|
2020-06-20 19:43:27 +00:00
|
|
|
- **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.
|
2019-05-27 20:15:26 +00:00
|
|
|
|
|
|
|
## This script does _not_
|
|
|
|
|
2020-06-20 19:43:27 +00:00
|
|
|
- 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.
|
2019-05-27 20:15:26 +00:00
|
|
|
|
|
|
|
## Requirements
|
|
|
|
|
2020-06-20 19:43:27 +00:00
|
|
|
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**.
|
2020-06-21 12:46:11 +00:00
|
|
|
3. You need two little DNS records set on your domain registrar's site/DNS
|
2020-06-20 19:43:27 +00:00
|
|
|
server: (1) an **MX record** pointing to your own main domain/IP and (2) a
|
|
|
|
**CNAME record** for your `mail.` subdomain.
|
2020-06-22 21:09:49 +00:00
|
|
|
4. **A Reverse DNS entry for your site.** Go to your VPS settings and add an
|
2020-11-14 19:18:50 +00:00
|
|
|
entry for your IPv4 Reverse DNS that goes from your IP address to
|
|
|
|
`<yourdomain.com>` (not mail subdomain). If you would like IPv6, you can do
|
2020-10-18 03:22:57 +00:00
|
|
|
the same for that. This has been tested on Vultr, and all decent VPS hosts
|
2020-11-14 19:18:50 +00:00
|
|
|
will have a section on their instance settings page to add a reverse DNS PTR
|
2020-10-18 03:22:57 +00:00
|
|
|
entry.
|
2020-06-22 21:09:49 +00:00
|
|
|
You can use the 'Test Email Server' or ':smtp' tool on
|
|
|
|
[mxtoolbox](https://mxtoolbox.com/SuperTool.aspx) to test if you set up
|
|
|
|
a reverse DNS correctly. This step is not required for everyone, but some
|
2020-11-14 19:18:50 +00:00
|
|
|
big email services like Gmail will stop emails coming from mail servers
|
2020-06-22 21:09:49 +00:00
|
|
|
with no/invalid rDNS lookups. This means your email will fail to even
|
2020-11-14 19:18:50 +00:00
|
|
|
make it to the recipients spam folder; it will never make it to them.
|
2020-06-22 21:09:49 +00:00
|
|
|
5. `apt purge` all your previous (failed) attempts to install and configure a
|
2020-11-14 19:18:50 +00:00
|
|
|
mail server. Get rid of _all_ your system settings for Postfix, Dovecot,
|
2020-06-20 19:43:27 +00:00
|
|
|
OpenDKIM and everything else. This script builds off of a fresh install.
|
2020-12-07 02:08:30 +00:00
|
|
|
6. Some VPS providers block mail port numbers like 25, 933 or 587 by default.
|
|
|
|
You may need to request these ports be opened to send mail successfully.
|
|
|
|
Vultr and most other VPS providers will respond immediately and open the
|
|
|
|
ports for you if you open a support ticket.
|
2019-05-27 20:15:26 +00:00
|
|
|
|
2020-06-20 19:43:27 +00:00
|
|
|
## Post-install requirement!
|
2019-05-27 20:15:26 +00:00
|
|
|
|
2020-07-10 18:36:29 +00:00
|
|
|
- After the script runs, you'll have to add additional DNS TXT records which
|
|
|
|
are displayed at the end when the script is complete. They will help ensure
|
|
|
|
your mail is validated and secure.
|
2019-05-27 20:15:26 +00:00
|
|
|
|
2020-06-20 19:43:27 +00:00
|
|
|
## Making new users/mail accounts
|
2019-05-27 20:15:26 +00:00
|
|
|
|
2020-06-20 19:43:27 +00:00
|
|
|
Let's say we want to add a user Billy and let him receive mail, run this:
|
2019-06-11 05:56:46 +00:00
|
|
|
|
2020-06-20 19:43:27 +00:00
|
|
|
```
|
|
|
|
useradd -m -G mail billy
|
|
|
|
passwd billy
|
|
|
|
```
|
|
|
|
|
|
|
|
Any user added to the `mail` group will be able to receive mail. Suppose a user
|
2020-12-07 02:08:30 +00:00
|
|
|
Cassie already exists and we want to let her receive mail too. Just run:
|
2020-06-20 19:43:27 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
usermod -a -G mail cassie
|
|
|
|
```
|
|
|
|
|
2020-09-05 01:55:32 +00:00
|
|
|
A user's mail will appear in `~/Mail/`. If you want to see your mail while ssh'd
|
2020-07-10 18:36:29 +00:00
|
|
|
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:
|
2020-06-20 19:43:27 +00:00
|
|
|
|
|
|
|
## 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
|
|
|
|
|
2020-11-14 19:18:50 +00:00
|
|
|
In previous versions of emailwiz, you also had to log on with *only* your
|
|
|
|
username (i.e. `luke`) rather than your whole email address (i.e.
|
2020-12-07 02:08:30 +00:00
|
|
|
`luke@lukesmith.xyz`), which caused some confusion. This is no longer the
|
2020-11-14 19:18:50 +00:00
|
|
|
case.
|
2020-06-20 19:43:27 +00:00
|
|
|
|
|
|
|
## Benefited from this?
|
2019-05-28 00:12:11 +00:00
|
|
|
|
2020-11-14 19:18:50 +00:00
|
|
|
I am always glad to hear this script is still making life easy for people! 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).
|
2020-06-22 20:35:13 +00:00
|
|
|
|
|
|
|
## Troubleshooting -- Can't send mail?
|
|
|
|
|
|
|
|
- Always check `journalctl -xe` to see the specific problem.
|
2020-11-14 19:18:50 +00:00
|
|
|
- Check with your VPS host and ask them to enable mail ports. Some providers
|
|
|
|
disable them by default. It shouldn't take any time.
|
2020-07-10 18:36:29 +00:00
|
|
|
- Go to [this site](https://appmaildev.com/en/dkim) to test your TXT records.
|
2020-06-22 20:35:13 +00:00
|
|
|
If your DKIM, SPF or DMARC tests fail you probably copied in the TXT records
|
|
|
|
incorrectly.
|
|
|
|
- If everything looks good and you *can* send mail, but it still goes to Gmail
|
|
|
|
or another big provider's spam directory, your domain (especially if it's a
|
|
|
|
new one) might be on a public spam list. Check
|
|
|
|
[this site](https://mxtoolbox.com/blacklists.aspx) to see if it is. Don't
|
|
|
|
worry if you are: sometimes especially new domains are automatically assumed
|
2020-12-07 02:08:30 +00:00
|
|
|
to be spam temporarily. If you are blacklisted by one of these, look into it
|
2020-06-22 20:35:13 +00:00
|
|
|
and it will explain why and how to remove yourself.
|
2020-12-07 20:19:33 +00:00
|
|
|
- Check your DNS settings using [this site](https://intodns.com/), it'll report
|
|
|
|
any issues with your MX records
|
|
|
|
- Ensure that port 25 is open on your server.
|
|
|
|
[Vultr](https://www.vultr.com/docs/what-ports-are-blocked) for instance
|
|
|
|
blocks this by default, you need to open a support ticket with them to open
|
|
|
|
it. You can't send mail if 25 is blocked
|