aboutsummaryrefslogtreecommitdiff
path: root/src/blog/2022-10-19-email-setup
diff options
context:
space:
mode:
Diffstat (limited to 'src/blog/2022-10-19-email-setup')
-rw-r--r--src/blog/2022-10-19-email-setup/email-setup.md201
1 files changed, 201 insertions, 0 deletions
diff --git a/src/blog/2022-10-19-email-setup/email-setup.md b/src/blog/2022-10-19-email-setup/email-setup.md
new file mode 100644
index 0000000..849efc6
--- /dev/null
+++ b/src/blog/2022-10-19-email-setup/email-setup.md
@@ -0,0 +1,201 @@
1# Keeping my email sorted (the hard way)
2
3I have recently made some changes to my email setup. In this post I'll
4explain the motivation behind these changes and what I did in practice.
5
6## Self-hosting?
7
8When I got my virtual machine up and running at
9[openbsd.amsterdam](https://openbsd.amsterdam/) - the one where this
10website is hosted - I originally planned to host my private email
11server there too. I knew this was probably a hard task, but you know,
12everything is hard until you learn how to do it.
13
14I wanted to do this for a couple of reasons. The main one was to use my
15`@tronto.net` email address, but I also liked the idea of staying away
16from large internet companies (my main email address was connected to my
17Google account). Not that there is anything inherently wrong with using
18services from this big companies, but I like the idea of not being too
19dependent on them.
20
21After reading
22[a nice tutorial at poolp.org](https://poolp.org/posts/2019-09-14/setting-up-a-mail-server-with-opensmtpd-dovecot-and-rspamd/)
23I was a bit discouraged. The guide was well-written, all the steps seemed
24doable if taken one by one, and I was happy to have dug into this topic
25because I learned a lot. However, an email server apparently consists of
26a lot of moving pieces: an smtp server, spam filter, DNS, DKIM... it is
27a lot to keep track of. Even assuming that I would be able to set this
28thing up AND to keep in mind what each of these pieces does, as soon as a
29problem of any kind arises - config-breaking updates? domain registration
30expiring? me messing up with my VM and making it unreachable? - I knew I
31had to be one to fix the mistake. And I cannot afford to be immediately
32available whenever something bad happens. Sometimes I might just have a
33full week were I don't have time to fiddle around with smtpd and whatnot,
34and I can't afford being unreachable via email for a week.
35
36## My old setup (until September 2022)
37
38Having abandoned the idea of self-hosting, I looked for alternatives. I
39figured that if my goals were just to use my own domain and stay away
40from Google, I could sign up for a smaller email provider that offers
41custom domains. It turns out there are a lot of them. After some careful
42considerations I decided to go with [mailbox.org](https://mailbox.org). I
43like their transparency and privacy focus and the fact that they are
44based in the EU. I pay 3€ per month (the 1€ tier does not offer
45custom domains) and I am happy with their service.
46
47Setting up the server side was quite simle. Using custom domains
48requires a tiny bit of work, but it was all well explained in the
49[FAQs](https://kb.mailbox.org/en/private/custom-domains).
50
51On my local machine I used (and still use) the amazing
52[mblaze](https://github.com/leahneukirchen/mblaze), which is essentially
53[MH](https://en.wikipedia.org/wiki/MH_Message_Handling_System)
54for [Maildir](https://en.wikipedia.org/wiki/Maildir) folders.
55In practice, mblaze is a set of commands to manage emails directly
56from the command line, without using a graphical environment or a
57[TUI](https://en.wikipedia.org/wiki/Text-based_user_interface) like
58[Mutt](https://en.wikipedia.org/wiki/Mutt_(email_client)). This system
59is incredibly flexible, check it out if you don't know it!
60
61Being just a mail user agent, mblaze cannot retrieve or send
62email. These tasks can be accomplished by other small pieces of
63software: I used [msmtp](https://marlam.de/msmtp) for sending
64email and [mpop](https://marlam.de/mpop) for downloading it
65from mailbox.org's server. As the name suggests, mpop uses the
66[POP3](https://en.wikipedia.org/wiki/Post_Office_Protocol)
67protocol instead of the more common
68[IMAP](https://en.wikipedia.org/wiki/Internet_Message_Access_Protocol).
69The main difference is that POP3 simply retrieves your email, while
70IMAP keeps the server and client folders synchronized. There are many
71advantages and disadvantages to this choice, I won't go into detail on
72them in this post.
73
74As for my other devices, my local mailfolder is kept in sync with my
75server using [syncthing](https://syncthing.net). I also use an amail
76client on my phone with IMAP, connected directly to the mail server.
77
78## Nitpicking
79
80Since I am subscribed to a couple of high-traffic mailing lists that
81I read just for curiosity, it is necessary for me to have an easy way
82to download and view regular emails separately from that coming from
83mailing lists.
84
85This was kinda easy to set up with mpop's filters, but my configuration
86was a bit of a hack. One disadvantage of this soution was that it
87only solved the problem on my laptop(s). On my webmail and on my phone,
88my inbox was a complete mess of mailing lists, newsletter and a few
89important emails.
90
91After thinking about it for a while I figured that an elegant solution
92would be to set up alternative email addresses for receiving mailing
93list emails, like `list@tronto.net`. Then I would manage those different
94mailboxes separately.
95
96Setting the aliases up on mailbox.org was easy, but unfortunately all my
97`@tronto.net` address used the same inbox, so I did not solve any problem
98at all. I could add some sub-folders and set up filters so that incoming
99mail gets sorted out, but the app on my phone could not read sub-folders
100and mailbox did not allow top-level folders (or I could not find a way to
101create them). Besides, tinkering with IMAP folders was not something
102that I found particularly exciting.
103
104But there was another solution...
105
106## My current setup (since September 2022)
107
108I decided to try and redirect the mailing list emails to my personal
109server. Configuring OpenBSD's smtp to receive emails from one specific
110outside source (my mailbox.org account) and sort them into some local
111folders is order of magnitudes easier than setting up a full-fledged
112email server. No problems with DKIM, no incoming spam, no nothing.
113
114It took me a few hours to figure our how to do this, but in the
115end it is just a matter of configuring a few filters on mailbox.org
116and adding a couple of lines to `/etc/mail/stmp.conf`.
117
118### mailbox.org filters
119
120On my mailbox.org webmail I simply set up a filter to redirect any email
121sent to `list@example.com` (a made-up name for the mailing list I am
122subscribed to) to my private server. No copy of these emails is kept on
123the server, so they don't clutter my normal (IMAP) inbox. I risk missing
124a few of these emails if my server goes down, but it is a public mailing
125list and I can always check the archives online.
126
127I could not just send these emails to `something@tronto.net`, otherwise
128they would simply be taken care of by mailbox - the MX records for my
129domain point to their servers. But it turns out you can send mail to
130a server using its IP address, as long as the server is configured to
131accept such mail. So I set up the redirects to `list@[46.23.91.214]` -
132where `46.23.91.214` is the IP address of my server.
133
134### smtpd.conf
135
136The second step is configuring smtpd, OpenBSD's default mail server
137daemon, to deal with incoming email.
138
139First of all we need to list the virtual user `list` in
140`/etc/mail/aliases` so that any mail sent to it is interpreted as being
141sent to my regular user.
142
143```
144# cat 'list: sebastiano' >> /etc/mail/aliases
145```
146
147Then we have to change the line `listen on lo0` to `listen on all`
148in `/etc/smtp.conf`.
149
150Then we need to add an `action` and a `match` lines to the same file:
151
152```
153# cat << EOF >> /etc/mail/smtpd.conf
154> action "list" maildir "~/mail/list" alias <aliases>
155> match from any for rcpt-to "list@[46.23.91.214]" action "list"
156> EOF
157```
158
159And finally restart smtpd with `rcctl restart smtpd`.
160
161This does the trick: now all email I receive from the `list@example.com`
162mailing list is redirected by my mailbox account to my private server,
163where smtpd takes care of sending it to the mail directory `~/mail/list`.
164
165### No mpop needed
166
167Once the mail is delivered to `~/mail/list`, I can get it from there
168to my laptop in any way I like - for example using syncthing, like I
169do for all my important files. In this way the mailing list emails are
170regularly downloaded and kept in sync, and I don't need to use mpop to
171retrieve them.
172
173This is quite convenient, one less piece of software to keep track of!
174In fact, I can do the same for all other email I receive. I just need
175to set up the appropriate rules on mailbox: this time I want the mail
176to be sent to `sebastiano@[46.23.91.214]` and *a copy to be kept on the
177mailbox.org server*, so that I can easily access it from my phone's app as
178well. Then I add two slightly different lines to `/etc/mail/smtpd.conf`:
179
180```
181# cat << EOF >> /etc/mail/smtpd.conf
182> action "seb" maildir "~/mail/inbox" user sebastiano
183> match from any for rcpt-to "sebastiano@[46.23.91.214]" action "seb"
184> EOF
185```
186
187And the new setup is ready!
188
189### Sending email
190
191I did not change the way I send email: I still use msmtp.
192
193## Happy now?
194
195Yes, this new setup works and I am always happy when things work.
196Of course, one might make the case that things worked before as well...
197
198I am happy that I could work my way around a basic smtpd configuration.
199Besides being useful knowledge on its own, it may make a second attempt
200at self-hosting my email less daunting. I don't know if I am ever going
201to try that, though.

Generated with cgit - Back to sebastiano.tronto.net