# need help with setting up virtual mail accounts in postfix.



## hockey97 (Jan 23, 2012)

Hi, ok  I already made threads on here asking for help about my setup. Currently I have postfix set up with mysql and dovecot. I created 2 rows of data in mysql that creates a virtual mail user. Well anyways  I can use thunderbird e-mail client aka pop client. I can log in with these users accounts and I can send e-mails to other servers on the internet with aol, yahoo, gmail etc. Now the problem is when they try and reply back. My issue is that mail won't get delivierd to my server for these 2 mail users. I get an error saying something that it failed to lookup in the alias table for such a user. I checked my mysql connections and tested the postfix and it shows no errors.

So I don't think the config is messed up. I think I have no clue what type of information needs to be in the mysql database. So, I ask here can someone explain to me how mail is routed from an aol, yahoo, gmail account. To one of my account and what kind of information I need in my mysql database in order to have an operational account that can receive e-mails from the internet?

I have read many books many tutorials and spent about 4 years trying to get a working mail server. No book or tutorial I read explains what exactly I need in my mysql database, like for instance usernames can I just have it like bob? Or do I have to do it like this bob@domain.com? Do I have to use the mail record of my domain name  as the mail address for the user? Something like bob@mail.domain.com? I am confused and notice all tutorials I have seen and most books about postfix don't go into great detail as to what kind of data is needed in the database and its format.

All it says would be here is the table for your domains and here is the table for you users information login information etc and path to mailbox or mail directory. I have those set up. I can login as a user for our example it be bob. Passwords are hashed. Every thing is working fine expect I can't receive e-mails. So something is wrong with how my server recieves  the mail. Mainly I think the lookup tables are either setup wrong or I put wrong data or didn't but the data in the right format in the mysql database. I need someone to give me an example how mail will get sent to my mail server and how postfix actually delivers that mail. What does it look for meaning if I have it set up in mysql then I am sure the database table need to have such information.

How is it formatted? Also when they say domains what do they mean by that? My domain name? Or domain of the user? A.k.a. do they mean this:  domain.com  or do they mean  bob@domain.com or do they mean: mail.domain.com or do they mean bob@mail.domain.com? 

I am confused. Please do explain how postfix delivers it's mail? What tables would it look up and what kind of information it needs?


----------



## divdev (Jan 25, 2012)

For what you're saying looks like you are really confused about everything. I suggest you to start simple, do you really need a database? The more components you put on the system, the more complex, difficult and insecure it will be to implement and mantain.
Have you tried this how-to : FreeBSD Diary - Postfix Virtual Domains
The better way to solve a problem is first isolating the components or if possible removing what can be excluded.


----------



## hockey97 (Jan 26, 2012)

divdev said:
			
		

> For what you're saying looks like you are really confused about everything. I suggest you to start simple, do you really need a database? The more components you put on the system, the more complex, difficult and insecure it will be to implement and mantain.
> Have you tried this how-to : FreeBSD Diary - Postfix Virtual Domains
> The better way to solve a problem is first isolating the components or if possible removing what can be excluded.



Yes, I need a database. I need to host multiple domain names for their mail. I already was able to set up my own 2 accounts for my own domain by direct but need to now set them as virtual accounts. These virtual accounts right now can send e-mail but just can't receive any e-mail. It would give a aliase lookup failed error.  Which I don't know exactly what it means. I got two books on the subject setting up postfix to host multiple domain names to receive mail for. The book doesn't go into details. Just tells you how to get postfix to use mysql. Then tells you how to set the virual users up in the postfix config which I already have it. Then shows you what mysql tables to make. Doesn't explain the data being stored just the table and fields. Then later on talks about how to handle spam and much more then tells you how to test the postfix server to look for errors.

I followed those and in the test I get alias lookup failed. The problem I think is that the data stored in the mysql database isn't correct. I didn't put in the correct information or didn't follow a certain format. I found no book, no tutorial that actually gives me an example of data inputted into the database and explain what the purpose of each data. When I see table or field with name of domain, I assume it's something like domain.com. But for my domain name the mx record is something like mail.domain.com. So I am not sure if I have to use that name at all in one of this domain areas.

It's so confusing and I checked the manual and many tutorials, got two books from the library about how to config postfix. all never talks in detail what data needs to be stored in the mysql database to actually work.


----------



## redw0lfx (Jan 26, 2012)

As was asked in your previous posts for this issue (http://forums.freebsd.org/showthread.php?t=27841), can you post your postfix virtual configuration files and your mysql schema for the postfix database, and if possible, at least one record.


----------



## hockey97 (Jan 26, 2012)

redw0lfx said:
			
		

> As was asked in your previous posts for this issue (http://forums.freebsd.org/showthread.php?t=27841), can you post your postfix virtual configuration files and your mysql schema for the postfix database, and if possible, at least one record.



ya, I posted that information already. Let, me post it again.

here are the file:

Main.cf click here


Master.cf click here

mysql_relay_domain_maps.cf click here


mysql_virtual_alias_maps.cf click here

mysql_virtual_domain_maps.cf click here

mysql_virtual_mailbox_limit_maps.cf click here

mysql_virtual_mailbox_maps.cf click here

mysql_database click here


Postfix_error_logs click here


----------



## redw0lfx (Jan 27, 2012)

Your postfix error log tells you one important bit:


```
Jan 26 19:57:08 dpserver1 postfix/trivial-rewrite[47178]: warning: do not list domain demonicproductions.com in BOTH virtual_alias_domains and virtual_mailbox_domains
```

Remove virtual_alias_maps (comment out) as its referencing the same table for the domains you will locally receive mail for. The virtual_alias_maps is for doing something like [email='bob@demonicproductions.com]'bob@demonicproductions.com[/email]' aliased to 'root@localhost'.

main.cf

```
virtual_alias_maps = proxy:mysql:/usr/local/etc/postfix/mysql_virtual_domains_maps.cf
```

Also update your domains table, and set the domain to 'demonicproductions.com', not 'demononicproductions'.  Also, your domains table is being referenced by the mysql_relay_domain_maps.cf which is incorrect. That file should only reference domains that you relay for and forward to another MX host and don't have a mailbox directory for on that host.


----------



## hockey97 (Jan 27, 2012)

So should I comment out mysql_relay_domain_maps.cf?

I will make the changes now and see what happens. What do you mean the domain table? In the mysql database?

What about the mailbox location?

I have it to this:

```
/domain.com/bob/new
```

I just made the changes above and now I see no error.

I then tested the user lookup well the mail directory lookup.
Just to see if everything is working properly with postfix looking up information.
It returns the mail directory path.

The problem is that I tested the e-mail. I sent a mail from my aol account to my domain account and I see no error or anything but yet never seen it delivered.

I think thinking it's because my mail directory isn't properly setup.


I am thinking that I need to change it to this:


```
/etc/local/virtual/domain.com/bob/new
```

Or 


```
domain.com/bob/new
```

I am not 100% sure.

never mind got it to work.


----------



## redw0lfx (Jan 27, 2012)

Glad you got it working.  Your missing two tables that might be important for you in the future, but can easily be addded if they are.

Those two tables are 'transport' for the mysql_relay_domain_maps.cf and alias for the mysql_virtual_alias_maps.  Both are for extending the virtual mail accounts, for example, if you want to receive mail from bob@somedomain and forward to another MX host (one incoming smtp server to multiple mailbox servers), or if you want to create aliases for the virtual email addresses.

But like it was mentioned in one of the previous post, start simple and work your way up.


----------



## hockey97 (Jan 28, 2012)

redw0lfx said:
			
		

> Glad you got it working.  Your missing two tables that might be important for you in the future, but can easily be addded if they are.
> 
> Those two tables are 'transport' for the mysql_relay_domain_maps.cf and alias for the mysql_virtual_alias_maps.  Both are for extending the virtual mail accounts, for example, if you want to receive mail from bob@somedomain and forward to another MX host (one incoming smtp server to multiple mailbox servers), or if you want to create aliases for the virtual email addresses.
> 
> But like it was mentioned in one of the previous post, start simple and work your way up.



I now have a new problem but this time I think it's with dovecot. I just used my thunderbird and I can login to the server. I just can't send e-mail or receive e-mail. I still can see when I send an e-mail to my bob@domain.com account. I see the mail physically stored on the server in this path:


```
/etc/local/virtual/domain.com/bob/new/
```

When I send e-mail from my aol account. I get no error messages. No, seems like using Thunderbird I can't send mail and Thunderbird doesn't grab the new mail.


----------

