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.


Command line

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 semi-colon (;) 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 ('demoslice.com');

Note the use of backslashes (`) 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 ('testslice.com');

Users

Adding a user email and password takes the same format:

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

Three things here:

Firstly, similar to when adding the domain details, note the distinction between backslashes (`) 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@demoslice.com', ENCRYPT('secretpassword'));

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

INSERT INTO `users` (`email`, `password`) VALUES ('paul@testslice.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 paul@demoslice.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 'demoslice.com':

/home/vmail/demoslice.com

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

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

/home/vmail/demoslice.com/paul
...
/home/vmail/demoslice.com/onion

Sending an email to the second domain (in my case, paul@testslice.com) will create a 'testslice.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 we have done all of that we can start to use the mail server.

Note that some mail clients may present users with certificate warnings or errors if Courier is not configured to use your SSL certificate. Unfortunately we must leave resolving that issue as an exercise for the reader for now.

PickledOnion

Article Comments:

Jesper Christiansen commented Sat Sep 06 18:14:42 UTC 2008:

Nothing happens in my vmail dir.. wonder what I did wrong :(

PickledOnion commented Sun Sep 07 02:54:54 UTC 2008:

Jesper,

I don't know to be honest - all I can suggest at this stage is to go through all the articles and see what may have been misconfigured.

I have been through the whole series a couple of times with a literal set of copy and pastes and all works.

Sorry I can't give more help than that.

PickledOnion

Jesper Christiansen commented Sun Sep 07 16:52:04 UTC 2008:

I know that it is impossible for you to help me - since there are soo many factors in this, that makes it hard to pinpoint just one thing.

I was wondering, i havent set a MX record for my domain, is that why I cant send mail out? (im not quite sure what to set as the MX record) :/

Jesper Christiansen commented Sun Sep 07 16:56:56 UTC 2008:

Ah... Found your other article about mx records.. maybe that will make it work.. :)

Jason Sheedy commented Wed Sep 10 03:11:38 UTC 2008:

Hi Onion, many thanks for all your great articles. I has saved me so much time. I've just finished the series on email setup and am having a bit of trouble logging in via pop. It would be a nice addition if you would add some notes on testing the pop/imap connection remotely, to make sure everything is setup properly.

At this stage everything seems to be working properly for me except that I get a message saying that login failed when trying to pop one of the accounts i setup. I'm thinking it may have something to do with the password encryption used in mysql. I couldn't see anywhere in the courier config that tells it that the passwords are encrypted and which encryption algorithm is being used.

Anyhow, thanks again. Your rock dewd.

Spencer Alexander commented Thu Sep 11 16:24:13 UTC 2008:

Very well done again Señor Pickled. I've tried following other postfix-courier-mysql tutorials, and none compare to this. I can't wait for the next tricks you have up your sleeves. Keep up the good work.

Dave Dean commented Fri Sep 12 19:37:31 UTC 2008:

Hello.

I've followed all your great articles to the letter. I can add mail users to MySQL and send mail to them which appears in /home/vmail exactly as it should. However, I can not seem to connect to the accounts by POP to retrieve the email from my workstation email client. What settings should we be using? I've tried every combination I can think of with no success.

Cheers,

Dave

Rich Harrison commented Sun Sep 14 11:01:14 UTC 2008:

Hey, First up: great tutorials. I've gone from plain slice to almost email/web server in a day.

I'm having the same problems as the other guys though: everything's set up, users added to the database, mail hitting the /home/vmail folder etc but I can't log into the server via pop or imap (secure or not). I just get a response that the username or password was incorrect. Any help Mr P.O? This is the last thing holding me back from moving my domains away from the hell of shared hosting!

Thanks again.

PickledOnion commented Sun Sep 14 14:22:17 UTC 2008:

Hi,

I don't know what is happening with the settings you have - I have no issues with a normal pop or imap (secured or unsecured) connection from my mail clients (I have tested it in Thunderbird and OS X's Mail).

I have gone through the entire mail server series from a fresh Slice and it works every time.

I will investigate to see what may have been missed but am a little stumped as to a reason you would have issues.

All I can suggest at this stage is to examine the postfix and courier logs to see what error messages there may be.

PickledOnion.

Les commented Mon Sep 15 08:23:55 UTC 2008:

Another set of awesome tutorials! This helped me move away from gmail apps, and finally be more flexible n my email usage!

Any timelines for the anti spam / anti virus tutorials?

Dave Dean commented Tue Sep 16 17:27:23 UTC 2008:

Has anyone had any luck with their POP problems? I'm still stumped, I've checked everything I can think of (although I don't know where the Postfix and Courier logfiles are - n00by I know). My pop account is correctly finding the mail server, as it warns me that the SSL certificate is self certified, it detects the email address I'm trying to access (and can receive email from it sent from the server via the 'mail' command), but just doesn't like the password I'm giving it. I've tried inputting the password in the MySQL database on the server as both encrypted AND unencrypted, but neither way works.

Is there another configuration file that needs tweaking, I noticed there is a pop3d file for configuring POP in /etc/courier - should we be editing anything in that?

Dave D commented Tue Sep 16 18:02:30 UTC 2008:

Aha! I finally found the solution to my POP problems. It is to do with something in the courier installation article so I will post the solution there. Link:

http://articles.slicehost.com/2008/9/2/mail-server-courier-installation

marko commented Tue Sep 16 19:58:29 UTC 2008:

I'm struggling a bit with sending mail... In Thunderbird, translated to this example, I'm trying to log in as user 'paul' on the smtp server 'mail.demoslice.com' using TLS and password 'secretpassword'. But that's not working, the authentication fails. Is it wrong or I should check some saslauthd configuration again?

Dave D commented Wed Sep 17 11:27:45 UTC 2008:

Marko: It sounds like it might be a similar issue to the one that caused my POP problems, which I solved as mentioned above.

jc commented Thu Sep 18 01:13:09 UTC 2008:

I can receive just fine via pop, but still having trouble sending smtp. All clients say mail server is refusing connections or unresponsive. I'm trying to diagnose:

  1. Should I be able to telnet remotely to mail.domain1.com 25?
  2. Someone suggested saslfinger. I tried running 'saslfinger -c' and I got this output: Cannot find the smtpsaslpassword_maps parameter in main.cf. Client-side SMTP AUTH cannot work without this parameter!

I don't think that's actually required for the setup that we did in this tutorial, but I'm curious if anyone else gets this output with theirs as well and can still smtp.

jc commented Thu Sep 18 03:14:22 UTC 2008:

nevermind - I forgot my isp blocks port 25. Realized it when I telneted more servers. Use 587 instead. I followed this thread to get mine fixed: http://www.howtoforge.com/forums/showthread.php?t=4788

My /etc/postfix/master.cf file now looks like this:

smtp inet n - - - - smtpd 587 inet n - - - - smtpd

marko commented Thu Sep 18 12:35:32 UTC 2008:

Dave, thanks, but my /etc/courier/authmysqlrc is exactly as shown in that guide. I can also telnet from my home computer to the server on port 25.

marko commented Thu Sep 18 20:32:39 UTC 2008:

Ah, I realized that I didn't have some packages installed. I skipped the long apt-get install line in one the previous articles because I "already installed them" (postfix and mysql) - but didn't have libpam-mysql and libsasl2-modules-sql. Sorry for the noise and thanks a lot for these great guides!

Stan Kaufman commented Sat Sep 20 20:35:33 UTC 2008:

Could you please provide an example of adding a forwarding entry using the forwards table created here?

Like a number of others, I'm unable to solve the POP/IMAP login problems but would be happy just to forward incoming email to other destinations. Looking at the other postfix resources out there, it is clear that there are MANY ways to do anything, so a suggested way to accomplish this that fits with all your other excellent configurations. Thanks!

Stan commented Sat Sep 20 21:08:20 UTC 2008:

OK, that was trivially simple; the source and destination fields are simply full email addresses. The forwards table doesn't reference the users table at all.

ja11sop commented Sat Oct 04 21:10:45 UTC 2008:

For those who couldn't see anything in their /home/vmail directory I think the problem might be that you still have,

mydestination = $mydomain, localhost.$mydomain, localhost

in your

  • /etc/postfix/main.cf

file, instead of it being blank,

mydestination =

as mentioned in this previous article http://articles.slicehost.com/2008/9/2/mail-server-configuring-postfix-to-use-mysql-part-2

I had this problem and that solved it. Might be worth making that more obvious in the linked article btw. I overlooked this as I'd previously setup Postfix following an earlier article with meant I had already changed this line.

ja11sop commented Sun Oct 05 21:32:01 UTC 2008:

For those having trouble authenticating with POP remember that in these guides the username _is_ the email address so make sure you use user@domain.com instead of just user.

I'd also go back and check all the config options again. You might find a couple of typos. I know I did.

Michael Specht commented Sat Oct 11 01:49:10 UTC 2008:

Just thought I would add a comment on my experience. I have spent several hours trying to work out why I could not send & receive email, it seems some how I missed a step, this one in particular http://articles.slicehost.com/2008/9/2/mail-server-secure-connection-configuring-saslauthd. I'm not sure how but it took me several times walking through the setup to figure it out as everything seemed to be working expect email would not arrive.

Oh like others commenting without these articles from PickledOnion I would never have got my site up and running.

soc commented Mon Oct 13 04:04:37 UTC 2008:

I'm getting a permissions error in /var/log/mail.log (maildir delivery failed: create maildir file /home/vmail/mydomainadd.com/soc/tmp/1223869998.P7509.mail.mydomainadd.com: Permission denied)

jerome sniddler commented Fri Oct 24 00:22:08 UTC 2008:

I'm going to use MYSQL's 'encrypt' function rather than the 'MySQL 'ECNRYPT' function.', if that's okay.

Thanks for the article! I'm finding them invaluable, and some of the best resources I can find online for getting my server set up. Better navigation and sequence would really help, however.

rarebit commented Tue Nov 18 16:47:07 UTC 2008:

In the words of Pickled Onion whilst doing a Sean Connery impression, 'Nicshe', very!

mgs commented Tue Nov 18 17:59:41 UTC 2008:

Has anyone successfully managed to get POP/IMAP working with mail.app by following these tutorials.

The tutorials are excellent but it sure is hard to find out where you missed a step. I wish there could be more checkpoints where we establish things to be working.

PickledOnion commented Wed Nov 19 11:27:37 UTC 2008:

Jerome,

oops! I have fixed the typo :)

mgs - I have it running with Mail with no issues. Not sure what the problem may be.

PickledOnion

Ray commented Sat Nov 22 19:47:50 UTC 2008:

Hi,

Thanks for this set -- I like this style of tutorial because it's open-ended enough to learn more after you're done.

I think it would be useful if you consistently linked to prerequisite and follow-up articles in the body of each one. I did these over a few days, and it was useful to review what I had already done before I started. Links to help facilitate that would make them easier to use.

Looking forward to future posts!

-Ray

victoria commented Wed Dec 31 01:35:43 UTC 2008:

Hi, I have followed all the tutorials under the 'Email - mail server setup' series. Pardon me for being a sys admin idiot.. but I don't see any step here involving the set up of the MX records for the multiple domains. Surely we'll need to do that for the mail to work?

flyboyart commented Wed Dec 31 12:59:05 UTC 2008:

Finally got mailserver working on my slice and I'm now able to send and receive email from IMAP Apple Mail just fine (been pulling what's left of my hair out for a couple days on this!). While the tutorials from PO were great and it only took me 4 tries to get it all accomplished without typos and pasting errors (;=}), the configuration of IMAP in Apple Mail has confounded me for the past day. I finally got it working properly and thought I could save some others time by posting the settings that I used in Apple Mail. Here they are:

Incoming Mail Server

mail server: mail.yourdomain.com username: yourname@yourdomain.com password: <yourpassword> IMAP path prefix: INBOX port: 143 authentication: password

Outgoing Mail Server

server name: mail.yourdomain.com use default ports (25,465,587) do no use SSL Authentication: password user name: yourname@yourdomain.com password: <yourpassword>

After all this is typed in, click away to be asked to save these settings and return to the mail Apple Mail window. You should see you email account listed in the Mailboxes list so click on it and choose "Rebuild' from the Mailboxes menu item.

For me, these steps worked fine and now I can send and receive email using the mailserver on my slice.

Happy New Year Everyone!

Andrew B commented Sun Jan 11 04:57:41 UTC 2009:

Hi Pickle.. you have a great tutorial! Your tutorial is actually the third one I have used after rebuilding my slice and I keep running into the same problem when sending email to an outside address from outlook on my PC at home... 554 5.7.1 toemail@somedomain.com: Relay access denied

I thought this had to do with SASL settings, and was excited when I saw that you had that setup in your tutorial.. but now I don't know. I never setup the SSL Certificate for smtp because I didn't want to bother with it, and I commented out the 3 ttl lines in the postfix main.cf file.

Any ideas? That relay error isn't from my isp is it?

Andrew B commented Sun Jan 11 05:00:08 UTC 2009:

**Sorry I meant the 3 tls lines not ttl

Andrew B commented Wed Jan 14 03:34:48 UTC 2009:

Oops, scratch some of that... I meant to say I've rebuilt the slice inbetween several tutorials because I get that relay access denied error, and I think its because I did something wrong. Well, I'll keep at it, any help from anyone who knows what a relay access denied error is greatly appreciated!

Andrew B commented Wed Jan 14 05:44:28 UTC 2009:

Well, I can answer my own question... In outlook, I had to select the little option that said "MY outgoing server (SMTP) requires authentication" with "Use same settings as my incoming mail server" selected... Thanks Pickle... your tutorial is better than everyone's!!!! THANKS!

Dan M commented Mon Jan 19 17:52:20 UTC 2009:

How do you add a catch-all account for a given domain?

Dan M commented Tue Jan 20 19:46:20 UTC 2009:

Some extensive googling later, I can answer my own question.

Just add this to the forwards table:

source: @mydomain.tld destination: dest@mydomail.tld

IV commented Sun Jan 25 13:07:47 UTC 2009:

Thanks a lot!! flyboyart

Erik Barber commented Wed Jan 28 18:12:01 UTC 2009:

I would like to see a How-To for setting up email forwarding accounts. (instead of full blown email accounts)

I'm guessing this can be done in Mysql?

Thanks!!!!

Erik Barber commented Wed Jan 28 19:42:29 UTC 2009:

How-To for setting up email forwarding accounts. Insert code below into the 'forwards' table.

INSERT INTO forwards (source, destination) VALUES ('info@example.com', 'sales@example.com');

Ben commented Tue Feb 03 00:27:08 UTC 2009:

I am having issues with both POP and IMAP authentication. User name and password doesn't seem to go. My /var/log/mail.log has this to say:

Feb 3 00:11:03 mail pop3d: Connection, ip=[::ffff:XX.XX.XXX.XXX] Feb 3 00:11:04 mail pop3d: chdir Maildir: No such file or directory Feb 3 00:20:37 mail imapd: Connection, ip=[::ffff:XX.XX.XXX.XXX] Feb 3 00:20:38 mail imapd: chdir Maildir: No such file or directory

This leads me to believe that a file or directory doesn't exist somewhere. As a complete n00b when it comes to mail servers, I have no idea where to go next, but none of the above suggestions have worked. Any ideas?

Ben commented Tue Feb 03 01:29:30 UTC 2009:

Well, I seem to have fixed my problem. That instruction which suggests replacing the entire contents of the config file with the recommended settings was key (I had just made changes to make the settings compliant with the suggested ones). Replaced the file, restarted courier, and it worked right away! By the way, great articles, PO.

Ben commented Tue Feb 03 01:52:54 UTC 2009:

Shoot, spoke too soon. SMTP isn't working (using Mail.app hijacked a different existing SMTP server and using pop through gmail just spoofs stuff, I guess). Any insights?

snidely commented Fri Feb 13 02:52:05 UTC 2009:

Thank you so much for the wonderful articles. Really looking forward to the next ones.

One question though... using this MySQL method for multiple domains and users (and also for forwarding), what is the significance of the original "alias" file?

alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases

Does this file do anything anymore? Right now mine just haa a single forward to 'root'. Should I delete the entries from the file and replicate the functionality into the MySQL db instead?

Danny commented Thu Feb 19 00:29:53 UTC 2009:

This is truely an awesome article! I actually missed a step when I first started, but went through and fixed it, but now I am getting a weird error. Can anyone help me debug this?

Feb 19 00:27:41 mail postfix/pickup[5294]: EB7271083BA: uid=0 from=<root> Feb 19 00:27:41 mail postfix/cleanup[5002]: EB7271083BA: message-id=20090219002741.EB7271083BA@mail.sc-power.com Feb 19 00:27:42 mail postfix/qmgr[5001]: EB7271083BA: from=root@mail.scpower.com, size=311, nrcpt=1 (queue active) Feb 19 00:27:42 mail postfix/virtual[5366]: warning: maildir access problem for UID/GID=5000/5000: create maildir file /home/vmail/dannychrastil.com/danny/tmp/1235003262.P5366.mail.sc-power.com: Permission denied Feb 19 00:27:42 mail postfix/virtual[5366]: warning: perhaps you need to create the maildirs in advance Feb 19 00:27:42 mail postfix/virtual[5366]: EB7271083BA: to=danny@dannychrastil.com, relay=virtual, delay=0.06, delays=0.04/0/0/0.01, dsn=4.2.0, status=deferred (maildir delivery failed: create maildir file /home/vmail/dannychrastil.com/danny/tmp/1235003262.P5366.mail.sc-power.com: Permission denied)

Danny commented Thu Feb 19 14:59:46 UTC 2009:

Ok I figured out why I was getting the Permission denied error. It was as simple as chmod'ing the /vmail/ folder to the appropriate level.

damien commented Sat Feb 28 23:21:14 UTC 2009:

This is another great tutorial but there is no link to the next article. Can anyone let me know where to find the next article?

Nick Sergeant commented Mon Mar 02 18:44:42 UTC 2009:

At the end of the article, you mention:

However, there are some odds and ends to tie up.

One of which is to get courier to use your self-signed (or purchased) SSL certificate. Not configuring courier to use your certificate may cause errors with some mail clients and may cause your users to be presented with a certificate warning.

The next article looks at this simple process.

Was that next article ever written? Can't seem to find it, and sending email via SSL seems quite slow, for some reason. Using Apple Mail.

Gareth Fleming commented Wed Mar 04 22:02:39 UTC 2009:

Like you need to hear it again, thanks for the tutorials. They are a great introduction to non-BOFHs like myself.

However, I've hit a bit of a snag, and nothing I do is helping. Basically, after following the tutorials to the end, everything looks hunky doray until I try to set up a mail client (I've tried with Mail.app and Thunderbird). The client fails will connect, and authenticate (I think) but complains that an error was encountered 'Unable to open this mailbox'.

Anyone else seen this problem and have any suggestions?

I've used maildirmake to make all the folders that would be expected, like Drafts, Sent etc. as well as recreating the mailbox itself using maildirmake. Nothing is having the slightest impact.

Thanks again.

Nick commented Wed Mar 04 22:47:05 UTC 2009:

I found a very similar setup if you're looking for more mail server setup instructions here: http://flurdy.com/docs/postfix/

Gareth Fleming commented Thu Mar 05 13:42:02 UTC 2009:

OK, so the problem lay, predictably, between chair and keyboard. I had a typo in my /etc/courier/authmysqlrc file (SUBSTRING instead of SUBSTRING_INDEX) that meant that the mailbox that the client was being told to connect to was <domain>// instead of <domain>/<user>/. All sorted now.

Kevin Whitaker commented Mon Mar 23 18:43:59 UTC 2009:

Hello all.

Well, I've made it all the way through the process, but when I attempt to send a test mail through the command line, I get nothing in my vmail directory for my domain. I've done every step, including the self-signed cert, saslauth, and the courier setup. Unfortunately, I'm also kind of a *nix n00b. Could someone point me to the default location for the postfix/courier logs so that I can try and find what's wrong?

Thanks.

Kevin Whitaker commented Mon Mar 23 19:07:05 UTC 2009:

Ok, so I found my logs, and this is the output:

Mar 23 19:03:28 mail postfix/proxymap[12506]: warning: connect to mysql server 127.0.0.1: Access denied for user 'mailadmin'@'localhost' (using password: YES) Mar 23 19:03:28 mail postfix/trivial-rewrite[12525]: fatal: proxy:mysql:/etc/postfix/mysql-domains.cf(0,lock|fold_fix): table lookup problem Mar 23 19:03:28 mail postfix/cleanup[12505]: 5202A5846F: message-id=20090323190033.5202A5846F@mail.digitalchill.com Mar 23 19:03:29 mail postfix/qmgr[12498]: warning: problem talking to service rewrite: Success Mar 23 19:03:29 mail postfix/master[12494]: warning: process /usr/lib/postfix/trivial-rewrite pid 12525 exit status 1 Mar 23 19:03:30 mail postfix/trivial-rewrite[12526]: fatal: proxy:mysql:/etc/postfix/mysql-domains.cf(0,lock|fold_fix): table lookup problem Mar 23 19:03:31 mail postfix/qmgr[12498]: warning: problem talking to service rewrite: Success Mar 23 19:03:31 mail postfix/master[12494]: warning: process /usr/lib/postfix/trivial-rewrite pid 12526 exit status 1 Mar 23 19:03:31 mail postfix/master[12494]: warning: /usr/lib/postfix/trivial-rewrite: bad command startup -- throttling Mar 23 19:04:03 mail postfix/pickup[12497]: 3D7E558470: uid=1000 from=<admin>

It all seems to stem from not being able to access my SQL database. However, I've verified that the mailadmin login works, and that the password is set correctly in all of my postfix config files.

Damien commented Thu Mar 26 22:58:05 UTC 2009:

Hi Kevin,

I agree that the problem seems to be the SQL connection but you say that the user can login when tried (from the shell I guess you mean.) Can you try again and check that the user can use the 'mail' database also? If that works double check that the database is also set to 'mail' in /etc/courier/authmysqlrc.

Unfortunately the tutorial seems to end here. I don't believe it has been finished and although I have got this far I cannot go on. Can I suggest you send an email to slicehost (http://www.slicehost.com/contact/email) as I have to encourage them to finish the tutorial.

Kevin Whitaker commented Fri Mar 27 03:21:46 UTC 2009:

Well, I ended up just rebuilding my slice, and now I've got mail to this point and it's working. Guess I missed a step somewhere.

So, can I log into my mail server now?

Brendan commented Sun Mar 29 01:48:27 UTC 2009:

Great series. Thanks! Any idea when the next article is coming? Would love to get rid of these certificate warnings.

Arran Schlosberg commented Sat Apr 04 02:52:33 UTC 2009:

My slice seems to still be storing mail in /var/mail/username instead of /home/vmail/domain.com/username

Did I miss something somewhere?

Matt Rowbottom commented Thu Apr 09 18:41:15 UTC 2009:

If you are having trouble connecting via POP or IMAP, return to the email tutorials and work your way through them again from the top.

I was sure I had not missed anything, but by the time I completed Mail Server - Postfix and MySQL installation for the second time, my IMAP and POP connection were alive!

Thanks to Pickled Onion for the excellent tutorials. They are one of the primary reasons I signed up for a Slicehost account.

Jeff Schwab commented Mon Apr 13 23:35:26 UTC 2009:

A few notes for posterity:

1) When you configure your email client (e.g. Thunderbird), make sure your user name is "you@yourdomain.com", not just "you". (ja11sop wrote this, but I didn't get it at first, and it bears repeating).

2) If you want to use port 587, it's not enough to open the relevant port for iptables. You also have to tell postfix to listen for SMTP connections on that port. This means uncommenting the first "submission" line in the default /etc/postfix/master.cf, right after the smtp line.

3) Courier has an unusual IMAP setup. If you're using Thunderbird, go to the account preferences -> Server Settings -> Advanced, and set the IMAP server directory to INBOX.

Lee commented Sat Apr 18 00:32:58 UTC 2009:

If your SMTP keeps getting rejected when you try to send e-mails from a 3rd party app, make sure to check to see if SMTP authentication is on in your e-mail client's account settings. I just spent the last hour pouring over my main.cf before I realized that this was the problem.

Arran commented Mon Apr 20 10:14:39 UTC 2009:

I have several domains with MX records pointing to my slice (for this sake domain.com, other1.com, other2.com etc.) where the hostname of the slice is 'domain.com'.

I have followed all of these tutorials and everything works fine for domains otherX.com i.e. as long as I have user@otherX.com in the database then the directory /home/vmail/otherX.com/user is created and mail is stored there.

However for domain.com (which is also the hostname of the slice) all mail to user@domain.com gets stored in /var/mail/user if and only if 'user' is an actual OS user.

Is there any way that I can override this to have the database checked for virtual users if they are at the same hostname as the slice?

Arran commented Wed Apr 22 00:48:15 UTC 2009:

Solved my previous problem.

For anyone who is keeping their slice hostname as domain.com rather than mail.domain.com as done in the tutorials then changing mydomain to mail.domain.com in /etc/postfix/main.cf will avoid the above problem.

I'm not sure of any other complications that this may cause though.

squagle commented Wed Apr 29 00:31:57 UTC 2009:

If one wants to use this setup and have a black-hole (/dev/null) email address. The fastest way I've found to do that is make a domain called "dev" and a user "null@dev". The way it auto-magically figures out where a users mailbox is will turn null@dev into /dev/null and put the spam there for safe keeping.

I use this with forwards. so lets say getsAlotOfSpam@domain.com > null@dev. It will keeps ones catch-all 'clean(er)'

Also, maybe I didn't see it in my 15 times reading this tutorial but setting up postfix this way uses the mysql table instead of your /etc/aliases file. You'll need to transfer all items over to your forwards table.

Finally, because it does not use the aliases file you will need to make a domain such as mail.demoslice.com so your postmaster, root and similar accounts get collected (or forwarded)

Enjoy!

BBB commented Sun May 10 05:09:30 UTC 2009:

Once again, many thanks - working perfectly. For those experiencing the same problems I had, a few suggested things to check:

1.) /home/vmail not creating folders

--> I had a typo in mysql-->mail-->users

2.) Cannot send mail

--> Turned off SSL for mail out, worked fine. SSL for mail in only, I guess.

moped commented Thu May 28 19:10:22 UTC 2009:

if at the end of all this it doesn't work for you - check /var/log/syslog for postfix errors. i found a sql error from a typo in there which had eluded me for ages.

maybe a pointer like this could be added to the article?

thanks

moped commented Thu May 28 21:21:14 UTC 2009:

following through this, and it would appear that anyone can telnet in and send mail. this isn't right obviously, logging into email accounts on 587 works fine, so why is it open via telnet?

Trevor Wennblom commented Sat May 30 23:15:26 UTC 2009:

postfix was rejecting Mail.app messages with SSL_accept error from in mail.log

i found the solution posted by Dan Phiffer

checking the certificate showed that it was signed by localhost - the first certificate out of three received was a default from Courier for IMAP - which is why i could only use IMAP instead of POP and SMTP.

change these two files to fix certs:

/etc/courier/imapd-ssl

#TLS_CERTFILE=/etc/courier/imapd.pem
TLS_CERTFILE=/etc/ssl/certs/mailcert.pem


/etc/courier/pop3d-ssl

#TLS_CERTFILE=/etc/courier/pop3d.pem
TLS_CERTFILE=/etc/ssl/certs/mailcert.pem

altered /etc/postfix/main.cf to force the bug -

# smtpd_use_tls obsolete - http://www.postfix.org/TLS_README.html
# smtpd_use_tls = yes
# smtpd_tls_security_level = may
smtpd_tls_security_level = encrypt

restart everything

sudo /etc/init.d/postfix restart
sudo /etc/init.d/courier-authdaemon restart
sudo /etc/init.d/courier-imap restart
sudo /etc/init.d/courier-imap-ssl restart
sudo /etc/init.d/courier-pop restart
sudo /etc/init.d/courier-pop-ssl restart

Mail.app settings

Incoming Mail Server

Incoming Mail Server: demoslice.com User Name: paul@demoslice.com (note that the username includes the domain) Password: secretpassword

under Advanced

Port: 993 [check] Use SSL Authentication: Password

Outgoing Mail Server (SMTP)

Server Name: demoslice.com [radio] Use default ports [check] Use Secure Socket Layer Authentication: Password User Name: paul@demoslice.com Password: secretpassword

Trevor Wennblom commented Sun May 31 21:51:15 UTC 2009:

# outside emails will typically bounce since the third-party client will be disconnected
# "530 5.7.0 Must issue a STARTTLS command first (in reply to MAIL FROM command)"
# smtpd_tls_security_level = encrypt
smtpd_tls_security_level = may

Jgo commented Mon Jun 01 01:12:39 UTC 2009:

Great articles! And thankyou Flyboyart for the apple mail rundown. FINALLY GOT IT WORKING! How satisfying is that. Pickled Onion's are good...

Andrew Rodriguez commented Fri Jun 19 18:31:50 UTC 2009:

I had the problem where the directories under VMAIL were not being created. The problem was that when I cut and paste, word wrap split my lines on the following steps: http://articles.slicehost.com/2008/9/2/mail-server-configuring-postfix-to-use-mysql-part-2

Now, a hint on troubleshooting:

sudo less /etc/syslog.conf

This will give you the location of your log files for email

Andrew Rodriguez commented Fri Jun 19 19:02:52 UTC 2009:

Another issue that happened.

CUT & PASTE. On one occasion, I didn't grab the whole line and the other

Check your LOGS. Specifically: /var/log/mail.log

Andy commented Sun Jun 21 05:00:00 UTC 2009:

Hi, I wrote this in the article requests comments as well, figured I'd put this in here too. Can anyone explain how to pipe mail to a script like perl/shell/php?

Thanks, Andy

Rich commented Mon Jun 22 16:17:33 UTC 2009:

I've got the problem where folders aren't being created in /home/vmail after sending the email. Had a look in /var/log/syslog and i have a long set of these errors after restarting Postfix:

Jun 22 15:55:19 slice postfix/postfix-script[5546]: refreshing the Postfix mail system Jun 22 15:55:19 slice postfix/master[4942]: reload configuration /etc/postfix Jun 22 15:56:02 slice postfix/proxymap[5557]: fatal: dict_open: unsupported dictionary type: mysql: Is the postfix-mysql package installed? Jun 22 15:56:03 slice postfix/cleanup[5556]: warning: private/proxymap socket: service dictproxyopen: Success Jun 22 15:56:03 slice postfix/master[4942]: warning: process /usr/lib/postfix/proxymap pid 5557 exit status 1 Jun 22 15:56:03 slice postfix/master[4942]: warning: /usr/lib/postfix/proxymap: bad command startup -- throttling Jun 22 15:57:03 slice postfix/proxymap[5561]: fatal: dict_open: unsupported dictionary type: mysql: Is the postfix-mysql package installed? Jun 22 15:57:04 slice postfix/cleanup[5556]: warning: private/proxymap socket: service dictproxyopen: Success Jun 22 15:57:04 slice postfix/master[4942]: warning: process /usr/lib/postfix/proxymap pid 5561 exit status 1 Jun 22 15:57:04 slice postfix/master[4942]: warning: /usr/lib/postfix/proxymap: bad command startup -- throttling

Seems like somehow I missed the stage on installing this package? Sure I copy and pasted everything right.

allan commented Mon Jun 22 21:06:00 UTC 2009:

The documentation is excellent, but unless one is pretty much a full-time sysadmin, capable of, and regularly configuring and tweaking postfix, etc., a GUI front-end utility would be best. I suspect this is true for most slicehost users(?), otherwise, they would be working on company-hosted servers.

Thanks

Christophe (belgium) commented Wed Jun 24 22:25:34 UTC 2009:

Hi,

For some or another reason I can't manage to login using outlook or atmail.

I have followed the tutorials a couple of times.

Any suggestions? Christophe

Vojtech Vondra commented Thu Jul 16 07:51:58 UTC 2009:

Try: sudo reboot

login worked for me after that, perhaps the sasl auth daemon needed to be restarted ....

Michael commented Thu Jul 16 10:59:04 UTC 2009:

I just finished going through every email tutorial and got everything working 100%! I even got my email client (Evolution) to send and receive all my mail from three different email addresses on my slice. But just as a tip, remember the username you enter in your email client to access your slice is not just the beginning part of your email address, but it's the full email address you are configuring, like demo@demoslice.com. Also, for receiving mail, you should be able to use SSL, but to send mail, I had to configure mine to use TLS or No Encryption. Those tripped me up at first. I'm using Debian Lenny by the way. Thanks PickledOnion! You truly made the holy grail of all mail server tutorials :)

MetaEd commented Wed Jul 29 00:01:15 UTC 2009:

Here is an example of marking a mailbox as the catchall address for a domain.

Ordinary mailboxes:

INSERT INTO `users` (`email`, `password`) VALUES ('john@testslice.com', ENCRYPT('secretpassword1'));
INSERT INTO `users` (`email`, `password`) VALUES ('paul@testslice.com', ENCRYPT('secretpassword2'));
INSERT INTO `users` (`email`, `password`) VALUES ('george@testslice.com', ENCRYPT('secretpassword3'));
INSERT INTO `users` (`email`, `password`) VALUES ('ringo@testslice.com', ENCRYPT('secretpassword4'));

paul also gets the mail addressed to any unrecognized mailbox at the domain:

INSERT INTO `forwards` (`source`, `destination`) VALUES ('@testslice.com', 'paul@testslice.com');

Brian Armstrong commented Sat Aug 01 00:22:26 UTC 2009:

PO, keep em coming!

Looking forward to next articles, this email series is great but sort of leaves it hanging at the moment.

Brian Armstrong commented Sat Aug 01 00:49:55 UTC 2009:

If anyone is getting problems with being unable to login (via pop or otherwise) check out the comment by Dave D above, and the comment he made here: http://articles.slicehost.com/2008/9/2/mail-server-courier-installation

I was getting stuff like this in my /var/log/mail.log until I made the changes he suggested. It works now!

mail ~: sudo tail -f /var/log/mail.log [sudo] password for admin: Aug 1 00:24:54 mail pop3d: LOGIN FAILED, user=bounce@mydomain.com, ip=[::ffff:209.85.221.156] Aug 1 00:24:54 mail pop3d: authentication error: Input/output error Aug 1 00:25:22 mail pop3d-ssl: Connection, ip=[::ffff:209.85.221.92] Aug 1 00:25:22 mail pop3d-ssl: LOGIN FAILED, user=bounce@mydomain.com, ip=[::ffff:209.85.221.92] Aug 1 00:25:22 mail pop3d-ssl: authentication error: Input/output error Aug 1 00:26:50 mail imapd: Connection, ip=[::ffff:209.85.221.200] Aug 1 00:26:50 mail imapd: Disconnected, ip=[::ffff:209.85.221.200], time=0 Aug 1 00:27:00 mail pop3d: Connection, ip=[::ffff:209.85.221.8] Aug 1 00:27:00 mail pop3d: LOGIN FAILED, user=bounce@mydomain.com, ip=[::ffff:209.85.221.8] Aug 1 00:27:00 mail pop3d: authentication error: Input/output error

Joel Oliveira commented Thu Aug 13 03:32:55 UTC 2009:

where's the next article? it says "The next article looks at this simple process." ... but no link. Anyone know where this is?

Chris commented Wed Aug 19 10:50:13 UTC 2009:

An excellent series of articles. Got everything working at the first attempt and now intend to extend the server by adding anti-spam and anti-virus features. Thanks PO!

Bryan commented Sun Sep 06 08:48:29 UTC 2009:

Do these articles continue anywhere else? So far so good. :D

Thanks,

Bryan

StevenBullen commented Tue Sep 08 10:54:48 UTC 2009:

if you forget a password and need to update it you can use the following command.

UPDATE users SET password = ENCRYPT("secretpassword") where email='onion@demoslice.com';

Morgan Croney commented Sat Sep 12 15:37:00 UTC 2009:

Hi, I'm moving from another server and my domain is still pointing to the old server (say test.com).

When I do: mail morgan@test.com

Nothing shows up in /home/vmail

Do I need to update the DNS / point the domain name to this server in order for it to work?

Morgan commented Mon Sep 14 14:43:28 UTC 2009:

Resolved my earlier issue of no emails showing up in /home/vmail. Below is how I fixed:

  1. Checked the error logs (/var/log/mail.log) and noticed that there were database connection errors.
  2. Edited my /etc/mysql/my.cnf file to make the bind-address = 0.0.0.0 which allowed for both my dedicated ip address and 127.0.0.1 to connect to the database. (For some reason, mysql will not load for me if I set the bind address only to 127.0.0.1).
  3. Restarted mysql, postfix, and courier services (as shown in these tutorials) and it worked!

Also, I missed it before, but it was helpful to start with the email basics and sending email sections on http://articles.slicehost.com/email (I had jumped directly to the "Email - mail server setup" section the first time).

PickledOnion & Slicehost: thanks so much for these guides! They are really great & helpful.

IV commented Sun Sep 20 11:04:44 UTC 2009:

Hi, Some email servers refuse the emails that I sent: "host mxlibero2.libero.it[212.52.84.84] said: 553 Domain of sender address info@portuguespodcast.com does not exist. For further information contact your provider. If you are the provider,"

This email domain is the second that I've created on this email server. I can't receive emails from gmail sent to this address either.

Thanks in advance

Marion commented Thu Sep 24 19:57:09 UTC 2009:

I have read this article and others, however I am still not able to customize the sender address for one of the domains I have sitting on my slice. When sending mail (sms) it displays user@neogenisys.com (slice), however I want it to display noreply@sendablink.com (1 of the domains on the neogenisys slice). Please point me in the right direction so that I can resolve. Thank you in advance.

James Hiscock commented Wed Sep 30 08:13:20 UTC 2009:

If anyone is having the problem of being unable to send mail through SMTP, and have tried everything else out there on google (Like I had) it turns out what can be a problem with PAM is that if the MySQL password to access the database has a # in it (don't know about other special characters) PAM isn't encapsulating the password in quotes or backticks, which is apparently required.

Changing my password from one with a # in it to a long alphanumeric of various cases solved my SMTP Auth problems!

CC commented Sun Nov 15 14:31:32 UTC 2009:

How do I add aliases for my mailboxes?

Donald commented Thu Nov 19 00:00:42 UTC 2009:

@Brian Armstrong

I had the same error for logging in. During the mysql auth setup for courier i edited the file instead of deleting it.

doing this left the "MYSQLNAMEFIELD" set to "name". This will cause a mysql error if the name field does not exist in the table.

I commented out that option and now it works fine.

allan commented Mon Jan 25 15:05:22 UTC 2010:

For those who are having problems with /home/vmail delivery, some tips (already mentioned, but worth repeating):

Check /var/log/mail.err to see what might be causing a problem

In my case, a log message unable to connect to mysql server showed a hosts setting of 127.0.0.1' - I ran through the setup and checked the log several times before I saw the tick at the end of the host ip in the log.

jg commented Mon Feb 22 23:43:12 UTC 2010:

The aliases file is no longer used, how do I forward something to a script? ie: /home/demo/public_html/domain1.com/public/cli/index.php

?

Benjamin Rhodes commented Thu Feb 25 17:18:33 UTC 2010:

I can't thank everyone that has posted on these articles enough! You all made it wonderfully easy to set up my mail server.

Just incase anyone can't figure it out, if you want to forward to more than one email address you would do

insert into forwards values('email@domain.com', 'email1@domain.com,email2@domain.com, email3@domain.com');

Once again thanks for all the helpful comments!

Noah commented Tue Mar 23 10:25:04 UTC 2010:

I had to add the following to my /etc/mysqld/my.cnf (archlinux) to get vmail devliery to work:

skip-networking

bind-address = 0.0.0.0

jday commented Fri Mar 26 04:36:59 UTC 2010:

looking at the /var/log/syslog

can anyone decipher what this means?

Mar 25 17:56:42 mail postfix/cleanup[3385]: warning: private/proxymap socket: service dictproxyopen: Success
Mar 25 17:56:42 mail postfix/master[3381]: warning: process /usr/lib/postfix/proxymap pid 4521 exit status 1 Mar 25 17:56:42 mail postfix/master[3381]: warning: /usr/lib/postfix/proxymap: bad command startup -- throttling Mar 25 17:57:42 mail postfix/proxymap[4522]: fatal: dict_open: unsupported dictionary type: mysql: Is the postfix-mysql package installed?

jday commented Mon Mar 29 00:03:48 UTC 2010:

me again, I installed postfix-mysql and now I get a new error in the log:

mail pop3d: chdir Maildir: No such file or directory

running this command, it looks like my test emails are going to the correct location: sudo ls /home/vmail/mydomain.com/webmaster/new/

but when trying to use apple mail to retrieve the emails: The server returned the error: The attempt to send data to the server “(null)” failed.

using mail.mydomain.com as the incoming server and webmaster@mydomain.com as user name

rob ganly commented Sun Jun 27 15:27:41 UTC 2010:

excellent walkthroughs, thanks PO.

i have my mail server setup and working well but have a trivial question- my mail forwarding is working from any address except the one that i am trying to forward to.

for example if i send a mail from rob@somewhere.com to test@mydomain.com it correctly forward to desireddestination@emailaddress.com.

however if i send a mail from desireddestination@emailaddress.com to test@mydomain.com i'd expect it to be forwarded [back] to desireddestination@emailaddress.com. however this doesn't happen.

i often like to mail myself reminders etc. so it'd be handy if this could work. i'm also interested in why it doesn't work- anyone have any ideas?

rob ganly

Jered commented Mon Jun 28 22:01:11 UTC 2010:

Hm, you might check your mail server logs to see if it mentions receiving that mail and doing something with it. That would at least let you know if it's getting to the right mail server.

I'd also suggest checking your spam filter, if you have one. A lot of them will shove mail with the same To and From addresses into the spam folder, especially if it's something like a one-line message with a URL.

Vipul commented Mon Mar 14 05:49:52 UTC 2011:

Thank you for this great tutorial. You guys rock!

I have mail server up and running. One issue is when I send email using this mail server from mail.example.com I can see the email in /home/vmail but when I send an email from say gmail I dont see it delivered to the user. Am I missing something. How can I debug? Thanks!

Jered commented Mon Mar 14 14:36:21 UTC 2011:

It sounds like the MX record may not be set up for the domain. When sending the mail locally the mail server wouldn't feel the need to check DNS to see where the mail should go, but gmail would need that information to point it in the right direction. You might take a look at this article on MX records to see if a DNS change can fix the problem.

Matt commented Mon Mar 21 17:27:17 UTC 2011:

I've followed the whole series on this email set-up (so, THANKS very much for the very thorough and practical info!)

Now I've begun to tweak and extend what I've learned - having trouble integrating a vacation/auto-reply message into the vmail user(s) set-up. Have been investigating the use of vacation.db, vacation.msg, and .forward in the /home/vmail/domain_name/user_name directory. Any insight as to the best and simplest way to achieve this?

Jered commented Mon Mar 21 20:41:18 UTC 2011:

I've never done it myself, actually. You can try using the "vacation" package from aptitude, but that works as an extra program - basically you'd set up a forward for the user to a "pipe" that runs the autoresponder (some more details on that on this site. Otherwise it sounds like there are some third-party postfix management programs (like Postfix Admin) that include autoresponder functionality.

Mr. Grateful commented Mon Jan 09 15:21:35 UTC 2012:

After three days of w*y guides, I'm glad I finally found this one. Now I have a mail server set up with SMTP, IMAP and POP that works. Next step, using postfixadmin, spamassassin, clamav, amavis, proper SSL and other stuff. A long way to go, but at least I can send and receive email now!

aroneJent commented Wed Jun 05 15:43:24 UTC 2013:

[url=http://play-roulette.ca/]Roulette startegy[/url] is the affectionate of meet in which all combinations or bets entertain a common put up edge. No roulette scenario can be said to be preferably than another or can undertaking a win. There are many roulette blueprint tips in casino. They on on all sides playing a free roulette and betting on the tables that are outside. Payment fetching the event, a woman must venture on the chances that are home, for instance, Odd/Even, Red/Black, High/Low or possibly dozens or columns. Roulette strategie to go to casino players Roulette strategie is number the most interesting and in games payment gambling and since they were invented, the players accept at no time stopped discovery ways to carry off and defeat the place for roulette using diverse systems in return betting and strategies in return roulette. The critical ideal suitable roulette strategies is to impart you an use for the players and reducing the prestige of fate when playing the game. Any sagacious player could have a stab the advanced roulette strategies and with a little fortuity they can penetrate unconscious as winners. Roulette organized whole design and betting Most casino players play a joke on a laborious major effort while choosing the immediately roulette system strategy. The betting systems in the service of roulette are bromide of the crush ways of acquiring acquaintance on how to gain at roulette. They provender the contestant with some lenient tips. These systems not only register for the sake of roulette but also quest of other games in the casino. While starting to dramatize the willing, one should look not on for the casino that does not volunteer save compensation especially for online players who play free games.

aroneJent commented Wed Jun 05 15:44:14 UTC 2013:

[url=http://play-roulette.ca/]Roulette startegy[/url] is the affectionate of meet in which all combinations or bets entertain a common put up edge. No roulette scenario can be said to be preferably than another or can undertaking a win. There are many roulette blueprint tips in casino. They on on all sides playing a free roulette and betting on the tables that are outside. Payment fetching the event, a woman must venture on the chances that are home, for instance, Odd/Even, Red/Black, High/Low or possibly dozens or columns. Roulette strategie to go to casino players Roulette strategie is number the most interesting and in games payment gambling and since they were invented, the players accept at no time stopped discovery ways to carry off and defeat the place for roulette using diverse systems in return betting and strategies in return roulette. The critical ideal suitable roulette strategies is to impart you an use for the players and reducing the prestige of fate when playing the game. Any sagacious player could have a stab the advanced roulette strategies and with a little fortuity they can penetrate unconscious as winners. Roulette organized whole design and betting Most casino players play a joke on a laborious major effort while choosing the immediately roulette system strategy. The betting systems in the service of roulette are bromide of the crush ways of acquiring acquaintance on how to gain at roulette. They provender the contestant with some lenient tips. These systems not only register for the sake of roulette but also quest of other games in the casino. While starting to dramatize the willing, one should look not on for the casino that does not volunteer save compensation especially for online players who play free games.

Want to comment?


(not made public)

(optional)

(use plain text or Markdown syntax)