You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 5.3 KiB

5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
1 year ago
5 years ago
1 year ago
1 year ago
5 years ago
5 years ago
5 years ago
3 years ago
4 years ago
1 year ago
1 year ago
5 years ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. # Email server setup script
  2. I wrote this script during the grueling process of installing and setting up
  3. an email server. It perfectly reproduces my successful steps to ensure the
  4. same setup time and time again, now with many improvements.
  5. I'm glad to say that dozens, hundreds of people have now used it and there is a
  6. sizeable network of people with email servers thanks to this script.
  7. I've linked this file on Github to a shorter, more memorable address on my
  8. website so you can get it on your machine with this short command:
  9. ```sh
  10. curl -LO lukesmith.xyz/emailwiz.sh
  11. ```
  12. When prompted by a dialog menu at the beginning, select "Internet Site", then
  13. give your full domain without any subdomain, i.e. `lukesmith.xyz`.
  14. ## This script installs
  15. - **Postfix** to send and receive mail.
  16. - **Dovecot** to get mail to your email client (mutt, Thunderbird, etc.).
  17. - Config files that link the two above securely with native log-ins.
  18. - **Spamassassin** to prevent spam and allow you to make custom filters.
  19. - **OpenDKIM** to validate you so you can send to Gmail and other big sites.
  20. - The required SSL certificates if not already present.
  21. - **fail2ban** to increase server security, with enabled modules for the above
  22. programs.
  23. ## This script does _not_
  24. - use a SQL database or anything like that. We keep it simple and use normal
  25. Unix system users for accounts and passwords.
  26. - set up a graphical web interface for mail like Roundcube or Squirrel Mail.
  27. You are expected to use a normal mail client like Thunderbird or K-9 for
  28. Android or good old mutt with
  29. [mutt-wizard](https://github.com/lukesmithxyz/mutt-wizard). Note that there
  30. is a guide for [Rainloop](https://landchad.net/rainloop/) on
  31. [LandChad.net](https://landchad.net) for those that want such a web
  32. interface.
  33. ## Prerequisites for Installation
  34. 1. Debian or Ubuntu server. I suited this script for
  35. [Vultr](https://www.vultr.com/?ref=8940911-8H) servers originally, but it
  36. works consistently on any normal setup.
  37. 2. DNS records that point at least your domain's `mail.` subdomain to your
  38. server's IP (IPv4 and IPv6). This is required on initial run for certbot to
  39. get an SSL certificate for your `mail.` subdomain.
  40. ## Mandatory Finishing Touches
  41. ### Unblock your ports
  42. While the script enables your mail ports on your server, it is common practice
  43. for all VPS providers to block mail ports on their end by default. Open a help
  44. ticket with your VPS provider asking them to open your mail ports and they will
  45. do it in short order.
  46. ### DNS records
  47. At the end of the script, you will be given some DNS records to add to your DNS
  48. server/registrar's website. These are mostly for authenticating your emails as
  49. non-spam. The 4 records are:
  50. 1. An MX record directing to `mail.yourdomain.tld`.
  51. 2. A TXT record for SPF (to reduce mail spoofing).
  52. 3. A TXT record for DMARC policies.
  53. 4. A TXT record with your public DKIM key. This record is long and **uniquely
  54. generated** while running `emailwiz.sh` and thus must be added after
  55. installation.
  56. They will look something like this:
  57. ```
  58. @ MX 10 mail.example.org
  59. mail._domainkey.example.org TXT v=DKIM1; k=rsa; p=anextremelylongsequenceoflettersandnumbersgeneratedbyopendkim
  60. _dmarc.example.org TXT v=DMARC1; p=reject; rua=mailto:dmarc@example.org; fo=1
  61. example.org TXT v=spf1 mx a: -all
  62. ```
  63. The script will create a file, `~/dns_emailwiz` that will list our the records
  64. for your convenience, and also prints them at the end of the script.
  65. ### Add a rDNS/PTR record as well!
  66. Set a reverse DNS or PTR record to avoid getting spammed. You can do this at
  67. your VPS provider, and should set it to `mail.yourdomain.tld`. Note that you
  68. should set this for both IPv4 and IPv6.
  69. ## Making new users/mail accounts
  70. Let's say we want to add a user Billy and let him receive mail, run this:
  71. ```
  72. useradd -m -G mail billy
  73. passwd billy
  74. ```
  75. Any user added to the `mail` group will be able to receive mail. Suppose a user
  76. Cassie already exists and we want to let her receive mail too. Just run:
  77. ```
  78. usermod -a -G mail cassie
  79. ```
  80. A user's mail will appear in `~/Mail/`. If you want to see your mail while ssh'd
  81. in the server, you could just install mutt, add `set spoolfile="+Inbox"` to
  82. your `~/.muttrc` and use mutt to view and reply to mail. You'll probably want
  83. to log in remotely though:
  84. ## Logging in from email clients (Thunderbird/mutt/etc)
  85. Let's say you want to access your mail with Thunderbird or mutt or another
  86. email program. For my domain, the server information will be as follows:
  87. - SMTP server: `mail.lukesmith.xyz`
  88. - SMTP port: 465
  89. - IMAP server: `mail.lukesmith.xyz`
  90. - IMAP port: 993
  91. ## Benefited from this?
  92. I am always glad to hear this script is still making life easy for people. If
  93. this script or documentation has saved you some frustration, donate here:
  94. - btc: `bc1qzw6mk80t3vrp2cugmgfjqgtgzhldrqac5axfh4`
  95. - xmr: `8A5v4Ci11Lz7BDoE2z2oPqMoNHzr5Zj8B3Q2N2qzqrUKhAKgNQYGSSaZDnBUWg6iXCiZyvC9mVCyGj5kGMJTi1zGKGM4Trm`
  96. ## Sites for Troubleshooting
  97. Can send or receive mail? Getting marked as spam? There are tools to double-check your DNS records and more:
  98. - Always check `journalctl -xe` first for specific errors.
  99. - [Check your DNS](https://intodns.com/)
  100. - [Test your TXT records via mail](https://appmaildev.com/en/dkim)
  101. - [Is your IP blacklisted?](https://mxtoolbox.com/blacklists.aspx)
  102. - [mxtoolbox](https://mxtoolbox.com/SuperTool.aspx)