• Sales: 1-800-961-2888
  • Support: 1-800-961-4454

Mail Server - Adding domains and users to MySQL


Following from the previous article, we now have our firewall opening the correct ports.

Now we can start adding domains and users to the MySQL 'mail' database.

Contents

Overview

We're going to be using the MySQL command line to add the domains and users.

You can, of course, use PHPMyAdmin or other MySQL GUI if you prefer. I'll leave that to you.

However, if you are using a GUI to add the details, make sure that when you add a user's password, you enter it using the MySQL 'ENCRYPT' function.

Let's log into MySQL:

mysql -u root -p

You will be prompted to enter your MySQL root password.

Once logged in, ensure you are using the 'mail' database:

USE mail;

Note the semicolon (;) at the end of the command. This lets MySQL know the command is to be executed - nothing will happen if you leave it off.

Domains

To add a domain is very simple:

INSERT INTO `domains` (`domain`) VALUES ('democloudserver.com');

Note the use of backticks (`) in the first two fields and the use of single quotes (') when entering that actual value.

To add another domain uses exactly the same procedure:

INSERT INTO `domains` (`domain`) VALUES ('testdomain.com');

Users

Adding a user email and password takes the same format:

INSERT INTO `users` (`email`, `password`) VALUES ('paul@democloudserver.com', ENCRYPT('secretpassword'));

Three things here:

Firstly, similar to when adding the domain details, note the distinction between backticks (`) and single quotes (').

Secondly, you must use the MySQL 'ENCRYPT' function when adding the password.

Lastly, change the 'secretpassword' to a more secure one of your choosing!

To add another user for the same domain:

INSERT INTO `users` (`email`, `password`) VALUES ('onion@democloudserver.com', ENCRYPT('secretpassword'));

and to add a user for the 'testdomain.com' domain:

INSERT INTO `users` (`email`, `password`) VALUES ('jeff@testdomain.com', ENCRYPT('secretpassword'));

Once done:

quit;

That will place you back at the command prompt.

Reload Postfix

As we have made changes to database, we will need to reload postfix:

sudo postfix reload

Test

Have a look at where the mail will be physically located:

ls /home/vmail

You will see that the folder is empty.

The correct folders are only created on receipt of the first email.

So. let's do just that by sending an email from the command line:

mail jeff@democloudserver.com

Enter a subject and body, then enter a single period (.) to indicate the message is ended.

Now look at the /home/vmail folder:

ls /home/vmail

You will see a new folder has been created named 'democloudserver.com':

/home/vmail/democloudserver.com

You will need sudo permissions to go any further and examine the contents of the democloudserver.com folder.

However, for each user under democloudserver.com a folder will be created. If we look back up to when I created my users, I had 'jeff' and 'onion'. I sent a new email to each user and now the folder structure looks like:

/home/vmail/democloudserver.com/jeff
...
/home/vmail/democloudserver.com/onion

Sending an email to the second domain (in my case, jeff@testdomain.com) will create a 'testdomain.com' folder and so on.

Make sure you send an email to each account you create - this will ensure the file structure is created.

Summary

Adding domains and multiple users is very easy using the MySQL command prompt.

Once created, send an email to the new user and the relevant file structure will be automatically created.

Now the mail server should be ready for use.

Previous Article



© 2011-2013 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License


See license specifics and DISCLAIMER

17 Comments

I finished the article series but i cannot make Outlook settings. How can i make outlook settings. Outlook is able to receive mails from server from address mail.domainname.com, but fails to send via smtp.

Hey Cihan - what port number are you using for your outgoing smtp server? Trying using a standard of 25. Let us know if this works for you.

Hi rae.cabello, i used both 25 and 587 for smtp. i am able to connect from other server to send email remotely via smtp, but failed to set it up on my local computer.

Hey Cihan, you can try port 2525 as well. Since you're able to set it up on a remote server, you may have something in your network blocking that particular port (firewall?) which may be preventing mail to go out. Feel free to call our support line and we can get some more details from you to help identify the cause.

I followed all pages of this tutorial. After sending test email I don't see any folder in /home/vmail what is wrong?

Have you [created the vmail user](http://www.rackspace.com/knowledge_center/index.php/Mail_Server_-_Vmail_User_and_Mailboxes) in one of the previous articles? You should also make sure [vmail was added to the postfix config](http://www.rackspace.com/knowledge_center/index.php/Mail_Server_-_Configuring_Postfix_to_Use_MySQL) as well as to the [courier config](http://www.rackspace.com/knowledge_center/index.php/Mail_Server_-_Courier_Installation). The postfix config is the most likely culprit for this problem if you did create the vmail user.

I seem to be doing something wrong. I've tried following the directions exactly (4 times, including doing a complete rebuild of my server and then following the directions again) and I can't do any SMTP stuff. I'm able to download messages for my accounts from my personal computer, but I can't send emails by SMTP from my computer. When I ssh in, the sendmail command works fine. While I'm in ssh, I can do telnet my-ip 25 and I get 220 my.com ESMTP Postfix (Ubuntu), however, when I'm not ssh'd into my server, just at my personal computers prompt, when I do telnet my-ip 25 nothing happens and I eventually get:

telnet: connect to address my-ip: Operation timed out
telnet: Unable to connect to remote host

My Firewall settings all seem correct. I've also tried removing all the settings from my firewall, and still nothing happened.

I've slightly fixed the problem by switching to port 587, but now after trying to send mail I get:

5.7.8 Error: authentication failed: no mechanism available.

Postfix server are often configured to allow SMTP connections only from the host machine by default. That's likely what's happening, from your description. You might try checking your settings against another article on setting up postfix:

http://www.rackspace.com/knowledge_center/index.php/Postfix_-_Basic_Settings_in_main.cf

And check some advice on testing with telnet in this article:

http://www.rackspace.com/knowledge_center/index.php/Postfix_-_Using_Telnet_to_Test_Postfix

We usually recommend using a third party to send email from a remote client, like Gmail or Rackspace Email, since it can be hard to maintain an SMTP server that allows sending from remote clients. If you do, make sure you at least test it to make sure it isn't an open relay once you have everything working to your satisfaction. You can do that from this site:

http://www.abuse.net/relay.html

I found the problem! It's a mistake on my part. When changing to port 587 for SMTP instead of port 25 I had the chroot option set in /etc/postfix/master.cf, but it should have not been set.

Aha! That'll do it all right. Glad you found a solution, CS, and thank you for posting it here for any other people who may run into the same issue in the future.

So I tested the mail server in two ways: a) sent an email directly to the newly just created email account, and 2) telnet as you suggested.

Both methods worked and I was able to go into the directory and verify the messages.
Below is the output from the telnet output:


telnet topitoff-cupcakes.com 25
Trying 50.57.228.145...
Connected to topitoff-cupcakes.com.
Escape character is '^]'.
220 helen.topitoff-cupcakes.com ESMTP Postfix (Debian/GNU)
HELO andi.topitoff-cupcakes.com
250 helen.topitoff-cupcakes.com
mail from:<andi@topitoff-cupcakes.com>
250 2.1.0 Ok
rcpt to:<kalyn@topitoff-cupcakes.com>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
subject: test message
this is the body of the message!
.
250 2.0.0 Ok: queued as B2A691828C
quit
221 2.0.0 Bye
Connection closed by foreign host.

I followed the directions, but when i send mail such as from the example "mail jeff@democloudserver.com", i don't see any content in /home/vmail.

Also setting the up a client ( OS X mail) for some reason it doesn't take the password.

1. I doubled checked the database and everything checks out fine with i test it by "testsalauthd".

2. After seeing the mail logs, the first error I noticed was the certificate had the wrong extension so that's correct.

3. Now the other error that's in the mail logs is:
mail.info:
Jun 29 11:27:47 helen imapd-ssl: LOGIN FAILED, method=PLAIN, ip=[::ffff:50.81.64.168]
Jun 29 11:27:47 helen imapd-ssl: authentication error: Input/output error

mail.warn
Jun 29 11:23:15 helen imapd-ssl: authentication error: Input/output error
Jun 29 11:27:47 helen imapd-ssl: authentication error: Input/output error




I'm not really sure what the problem was, but I started from the beginning and now seems like everything is working. Thanks for your help.

The article refers to "backslashes", it should be "backticks"? Not sure they are needed here anyhow.

You're correct, those should have been labelled as backticks. The article has been updated accordingly.

Backticks are used in place of single-quotes when you might need to use special characters or want to use a field name that might be a keyword in SQL. Some admins use them as a sort of future-proofing, so that a database server upgrade later that introduces a new keyword won't conflict with their field naming scheme.

Add new comment