# Setting up mail server on Contabo Server

Hello,

I recently had to set up a mail server. However, I encountered some issues which I would love to discuss here.

I had to use the Contabo server because Amazon is not enabling port 25 for my team on the AWS EC2 instance. After setting up the VPS on Contabo, connect to your server using the default username "**admin**" and the chosen password. 


- Change the server hostname to your domain

```
sudo hostname host.domain.tld 
``` 


- Install webmin Software and Postfix as the SMTP software

```
wget http://software.virtualmin.com/gpl/scripts/install.sh 
``` 

``` 
sudo /bin/sh install.sh 
``` 


- Webmin configuration
Your Webmin will be available on port 10000 of your domain or subdomain.
Configure it using the guidance in the reference below this article.


- Create a virtual server
Create a virtual server and login into the newly created virtual using SSH.
Grant Sudo privileges to the virtual server default user, if the username is "seunuser", then use the following command to grant the user sudo privileges from the "admin" user account.


```
sudo usermod -a -G sudo seunuser
``` 

The above user credentials will work, however, it is good practice to limit the user account to only what its expected to do "send email". Therefore, create a new user account with just an email priviledge option.


- Create a user account email address
Create an account as shown in the screenshot below and which will be used for SMTP login. 


![ Create User](https://cdn.hashnode.com/res/hashnode/image/upload/v1652517303662/6Q1wL1rgJ.png align="left")


- Test the credentials
Goto https://www.smtper.net/ and test the above credentials. If it works, then you can skip to the conclusion, else, check the next point.

- Fix "Relay Access Denied"
If you are getting "Relay Access Denied". Tail your error log using the following command

```
sudo tail -n 20 /var/log/mail.log
``` 

My error log looks like the screenshot below

![error log](https://cdn.hashnode.com/res/hashnode/image/upload/v1652517698029/7dta209kN.png align="left")

The following command helps in resolving the issue


```
rm -r /var/run/saslauthd/
mkdir -p /var/spool/postfix/var/run/saslauthd
ln -s /var/spool/postfix/var/run/saslauthd /var/run
chgrp sasl /var/spool/postfix/var/run/saslauthd
adduser postfix sasl
``` 
[Credits](https://serverfault.com/a/721935)

Then restart your server manually from the Contabo server.

- Test the credentials Again

Your test should be successful now similar to the screenshot below.

![SMTP Test ](https://cdn.hashnode.com/res/hashnode/image/upload/v1652517928308/VN0eEwRBN.png align="left")



- Conclusion
I hope you find this helpful.
Thank you for your time.
Happy Coding


- References

1. https://h-educate.com/setup-smtp-server/
2. https://itsyndicate.org/blog/relay-access-denied-solution/
3. https://serverfault.com/questions/721925/postfix-smtpsaslauthd-autentication-failure
4. https://serverfault.com/questions/1017291/enabling-tls-ssl-on-postfix













