• Stars
    star
    1,527
  • Rank 30,669 (Top 0.7 %)
  • Language
    Shell
  • License
    GNU General Publi...
  • Created over 5 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Script that installs/configures a Dovecot, Postfix, Spam Assassin, OpenDKIM Debian web server

Email server setup script

This script installs an email server with all the features required in the modern web.

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, e.g. lukesmith.xyz.

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.

This script installs

  • Postfix to send and receive mail.
  • Dovecot to get mail to your email client (mutt, Thunderbird, etc.).
  • Config files that link the two above securely with native PAM 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.
  • Certbot SSL certificates, if not already present.
  • fail2ban to increase server security, with enabled modules for the above programs.

This script does not...

  • use a SQL database or anything like that. We keep it simple and use normal Unix system users for accounts and passwords.
  • set up a graphical web interface for mail like Roundcube or Squirrel Mail. You are expected to use a normal mail client like Thunderbird or K-9 for Android or good old mutt with mutt-wizard. Note that there is a guide for Rainloop on LandChad.net for those that want such a web interface.

Prerequisites for Installation

  1. Debian or Ubuntu server. I suited this script for Vultr servers originally, but it seems to work on most other default setups on different VPS providers.
  2. DNS records that point at least your domain's mail. subdomain to your server's IP (IPv4 and IPv6). This is required on initial run for certbot to get an SSL certificate for your mail. subdomain.

Mandatory Finishing Touches

Unblock your ports

While the script enables your mail ports on your server, it is common practice for all VPS providers to block mail ports on their end by default. Open a help ticket with your VPS provider asking them to open your mail ports and they will do it in short order.

DNS records

At the end of the script, you will be given some DNS records to add to your DNS server/registrar's website. These are mostly for authenticating your emails as non-spam. The 4 records are:

  1. An MX record directing to mail.yourdomain.tld.
  2. A TXT record for SPF (to reduce mail spoofing).
  3. A TXT record for DMARC policies.
  4. A TXT record with your public DKIM key. This record is long and uniquely generated while running emailwiz.sh and thus must be added after installation.

They will look something like this:

@	MX	10	mail.example.org
mail._domainkey.example.org    TXT     v=DKIM1; k=rsa; p=anextremelylongsequenceoflettersandnumbersgeneratedbyopendkim
_dmarc.example.org     TXT     v=DMARC1; p=reject; rua=mailto:[email protected]; fo=1
example.org    TXT     v=spf1 mx a: -all

The script will create a file, ~/dns_emailwiz that will list our the records for your convenience, and also prints them at the end of the script.

Add a rDNS/PTR record as well!

Set a reverse DNS or PTR record to avoid getting spammed. You can do this at your VPS provider, and should set it to mail.yourdomain.tld. Note that you should set this for both IPv4 and IPv6.

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 too. Just run:

usermod -a -G mail cassie

A user's mail will appear in ~/Mail/. If 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 email clients (Thunderbird/mutt/etc)

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: 465
  • IMAP server: mail.lukesmith.xyz
  • IMAP port: 993

Benefited from this?

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, donate here:

  • btc: bc1qzw6mk80t3vrp2cugmgfjqgtgzhldrqac5axfh4
  • xmr: 8A5v4Ci11Lz7BDoE2z2oPqMoNHzr5Zj8B3Q2N2qzqrUKhAKgNQYGSSaZDnBUWg6iXCiZyvC9mVCyGj5kGMJTi1zGKGM4Trm

Sites for Troubleshooting

Can't send or receive mail? Getting marked as spam? There are tools to double-check your DNS records and more:

More Repositories

1

voidrice

My dotfiles (deployed by LARBS)
Shell
4,189
star
2

mutt-wizard

A system for automatically configuring mutt and isync with a simple interface and safe passwords
Shell
2,305
star
3

based.cooking

A simple culinary website.
CSS
2,148
star
4

LARBS

Luke's Auto-Rice Bootstrapping Scripts: Installation Scripts for My Arch Linux Meta-Distribution
Shell
1,985
star
5

st

Luke's fork of the suckless simple terminal (st) with vim bindings and Xresource compatibility.
C
1,591
star
6

dwm

Luke's build of dwm
C
777
star
7

dwmblocks

My status bar: my build of the modular dwmblocks
C
411
star
8

landchad

Landchad.net Website Tutorial Page
CSS
353
star
9

lb

Blog & RSS system in less than 100 lines of shell script
Shell
282
star
10

latex-templates

My LaTeX templates, bibliography file, etc.
TeX
208
star
11

lugo

Luke's Hugo Theme
HTML
157
star
12

dmenu

dmenu setup for LARBS
C
145
star
13

shadowchat

A simple Monero (XMR) superchat donation system in Go
Go
122
star
14

vul

Latin Vulgate Bible on the Command Line
Awk
107
star
15

md-website-cv

A system for CVs/resumes and websites based on markdown files
HTML
96
star
16

etc

Random files that could be of interest
83
star
17

grb

A cli-accessible Greek Bible with the Septuagint, SBL and Apocrypha
Awk
76
star
18

surf

Luke's build of the surf web browser
C
65
star
19

shortcut-sync

Luke's Scripts for bash, ranger and qutebrowser synchronization
Shell
59
star
20

vimling

Small vim scripts for writing IPA and other special characters
Vim Script
49
star
21

critique-of-reason

Term paper on Rationality
TeX
35
star
22

corpus-latinum

Luke's Latin Tagger and (under construction) Corpus
Python
26
star
23

go-webring

Go
25
star
24

scroll

Minor personal tweaks to suckless's scroll (for st)
C
24
star
25

syntax-without-syntax

Qualifying paper on how word orders are driven by prosodic parameters
TeX
18
star
26

scope-without-syntax

Quantifier scope ambiguities are derived entirely from pragmatic assumptions, implemented in Game Theory.
TeX
15
star