# Setting up a mail server on 9front
or How to struggle with mail
First I follow the setup from the FQA, modifying config files accordingly. But when testing, neither testing nor receiving mail works. I did tons of research, tried some debugging stuff but nothing worked. I abandoned.
After a few months, I tried again. I tried researching again, nothing. I also asked on the 9chat at 9p.zone for help (thank you guys, especially umbraticus) and I was told that my config was ok. But we didn't find out the issue.
But then I suddently have some inspiration and look at /sys/log/listen ...
```
tcp: /rc/bin/service/tcp587: '/rc/bin/service/tcp587' permission denied
```
First lesson: every file in /bin/service should be executable by anyone. In fact since I created this file, it didn't set the +x permission. I didn't pay attention because all the other services I needed were already there under !tcpXXX. Except for gemini, which strangely had the right permissions ... Don't ask.
After retrying to send myself an email, I see in /sys/log/mail errors:
```
error+ failed with error 'qer: creating data file /mail/queue/none/D.001204: '/mail/queue/none' permission denied
error+ '.
error+ The mailer `/mail/lib/qmail <stuff cut here>' returned error status 72.
```
But in fact I only received that mail because I tested at the same time creating the file tcp25, with exactly the same content as tcp587 in /bin/service . Which I removed again, so that to my surprise I didn't see any new email in the logs.
The problem is that port 25 is the one used to receive emails, and not 587. This is absolutely not mentionned in the FQA ... To be clearly improved I guess.
Now returning to the permission issue, after some help again from 9chat, reading listen(8) tells one that services located in /bin/service are executed as user none, which explains why /mail/queue/none/D.001204 couldn't be created: none has no permission of course !
The problem is now, what should I do to fix this issue ?
Asking again in the chat (thanks ori), it seems like /mail/queue/none shouldn't have been created at all, it should have been in /mail/queue/glenda.
The problem is was that by doing `mail -x
[email protected]`, it should have returned local!glenda thanks to the file in /mail/lib/rewrite instead of esthromeris.us.to!admin . I admit not really being sure about what the -x option does, I tried to check mail(1) and marshal(1) but I found nothing about it ... Anyway it exists.
In fact, the problem was that the FQA shows an outdated version of /mail/lib/rewrite.direct, but it still tells you to copy that rewrite.direct to rewrite. And the huge problem is that rewrite.direct is very misleading ! In it, there is that line
```
# replace YOURDOMAIN.DOM in the following rules with your domain name.
```
The only place where you see YOURDOMAIN.DOM is there
```
\l\.YOURDOMAIN\.DOM!(.*) alias \1
```
Thus I simply replaced it
```
\l\.esthromeris\.us\.to!(.*) alias \1
```
But the catch it that "\l", which gets replaced by $sysname ! (see rewrite(6)) Thus that regexp was checking for a domain $sysname.esthromeris.us.to , which my domain is just esthromeris.us.to ... You have to replace that one correctly
```
(esthromeris.us.to)!(.*) alias \2
```
(I put "esthromeris.us.to" in parenthesis so that I don't need to escape dots. I also replaced "\1" by "\2" because \n where n is a number matches what is inside an expression in parenthesis and I want to match what's after the '!')
And now, finally it works ! Doing `mail -x
[email protected]` returns me "local!glenda" as desired, and receiving mails finally works !
But there's still a catch (you bet): I still can't send any mail.
Allthough this time it isn't a misconfiguration problem, again thanks to ori for that, but my ISP is blocking outgoing connections to port 25. I can't do anything against that, I guess I will just not be able to send emails.
Well at least I can receive mails. That's still nice. I hope this writing will help you if you are struggling too in setting up your own mail server on 9front.
EDIT: I'm not running the mail server anymore, so even sending me mail to
[email protected] . Might revive it at some point, but don't count on it.