# How to install Postfix on FreeBSD 8.1 with MySQL?



## hockey97 (Aug 13, 2011)

Hi, I want to setup a mail server mainy postfix with mysql. I want to make my own php webmail interface to my website. I also want to use php to use the mail function to  use these accounts too... to automate e-mails to users. Like when they register they will have to verify their e-mail address. I need to learn how e-mails get passed and how I can make my mail serve to send e-mails and receive e-mails. 

Any good tutorials other then the manuals on here and postfix website. I already tried them and tried many other online tutorials I was able to follow the steps but still when I got to the point where I had to make mysql tables I got lost as to what information needs to be in that table. So I never got things to work at all. Yet, I was able to config postfix to use it's own mail maps system. I was able to send and receive mail. 

Any ideas of some good resources that can teach me how e-mail servers work and how I need to set my postfix mail server?


----------



## graudeejs (Aug 13, 2011)

http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/ports.html
ports(7)


----------



## hockey97 (Aug 13, 2011)

I know how to install postfix... from the ports. I just don't know how to config it to make mysql work with postfix. I need to learn how e-mail servers actually work.. how e-mails gets passed back and forth.


----------



## graudeejs (Aug 13, 2011)

This is about postgresql
http://wiki.bsdroot.lv/postfix:mailserver

In references section you will find links, that will lead you to postfix+mysql


----------



## hockey97 (Aug 13, 2011)

killasmurf86 said:
			
		

> This is about postgresql
> http://wiki.bsdroot.lv/postfix:mailserver
> 
> In references section you will find links, that will lead you to postfix+mysql



But, I need something for mysql. Want to use postfix with mysql. I already got the server isntalled. I just need to install postfix and then config/set it up to use mysql properly. But I need to learn how e-mails get transferred.  That way I can understand what I need to put in each table I create for the mysql table. I found many tutorials that explains each step on what to do. yet, they never explained the mysql database part where what information goes in what table. they  just show you how to create the table and then they said done. I am sure I got it working with mysql but the part I failed was the data stored in the mysql tables weren't proper. 

I can't find any tutorials or resources that explains each table made in mysql for postfix and what kind of information it needs. I want to shot multiple domain names e-mails.


----------



## graudeejs (Aug 14, 2011)

I told you check out reference section.
It contains links to howto postfix+mysql... I wrote that howto based on other howtos

If you don't know what each table do, then you have to read postfix documentation, to find out.
That's what I did


----------



## hockey97 (Sep 25, 2011)

graudeejs said:
			
		

> I told you check out reference section.
> It contains links to howto postfix+mysql... I wrote that howto based on other howtos
> 
> If you don't know what each table do, then you have to read postfix documentation, to find out.
> That's what I did



I looked through them and currently going through them. Just one question which I can't find an answer too.  What is an alias? I assume it's an e-mail name that you go by.


----------



## graudeejs (Sep 25, 2011)

With aliases:
if you receive mail to *wtf@alias.is*, it can be delivered to *hockey97@alias.is*

In other words, You can have single mailbox, but multiple email addresses, that can receive mail (for example)

Also check definition of alias in dictionary: http://dictionary.reference.com/browse/alias


----------



## hockey97 (Sep 26, 2011)

graudeejs said:
			
		

> With aliases:
> if you receive mail to *wtf@alias.is*, it can be delivered to *hockey97@alias.is*
> 
> In other words, You can have single mailbox, but multiple email addresses, that can receive mail (for example)
> ...



I know what the word means in the English language. Just didn't know what it means in the mail servers.  I know spys uses an alias name or you can call it a code name. they don't give out their real names but other agents would call them by that alias name.

I followed this tutorial: http://www.purplehat.org/?page_id=8

I am stuck at the mysql maps. I don't know if I have to create a new account with mysql under the name postfix  and give it a password. Where in the mysql maps it says password = postfix_sql_password       I assume that I need to type the password there the one that was created with that account which is the account name named postfix. So would I need to make a new account with mysql and create that postfix account? If so should I look at the mysql installation guide on the same site to follow the steps in making the new account?


----------



## hockey97 (Sep 26, 2011)

I just followed that tutorial on postfix using mysql. It isn't working. I created a mysql account for postfix. I then added the password to those mysql maps. Right now I can't send an e-mail out or get e-mails. Do I have to create some mysql data tables? to me it seems I have too. Yet, the tutorial dosen't show you how or show that you need too.


----------



## hockey97 (Oct 8, 2011)

Is there any tutorials on how to connect mysql with postifx. The tutorial provided dosen't talk about how mysql syncs with postfix. Like  how to name the mysql tables and what information to be stored in them in order for postfix to work properly.


----------



## Abriel (Oct 8, 2011)

http://www.freebsdonline.com/content/view/339/348/ check it.


----------



## hockey97 (Oct 8, 2011)

Abriel said:
			
		

> http://www.freebsdonline.com/content/view/339/348/ check it.



I checked that out. I setup the system via :  http://www.purplehat.org/?page_id=8 that tutorial. Would like to know of the mysql tables are the same name etc so there is no broken link.


----------



## graudeejs (Oct 8, 2011)

You can name them any way you want. Just need to adjust postfix config cf files


----------



## hockey97 (Oct 8, 2011)

Abriel said:
			
		

> http://www.freebsdonline.com/content/view/339/348/ check it.



I checked that out. I setup the system via :  http://www.purplehat.org/?page_id=8 that tutorial. Would like to know of the mysql tables are the same name etc so there is no broken link. I can see some similar sql commands. I understand sql code. I just don't understand what is needed for each map and what does each map do. I am using mysql for those maps. I assume the virtual domain maps are the ones where you type in your mx record domain. For example:  mail.domain.com   this be the mx record of our domain name that will be used for e-mail.

That domain table in mysql has that domain and the active field. This be the place where you put all mail domain names that you want to handle mail for. The virtual mailbox maps would be where you put the user name and the physical location of their mail where it's stored on the server. So for example:  user:bob  /  maildir:home/server/websites/domain/mail/bob Then you have a field if it's active. To allow mail or allow access to mail for that user. 

Got one more question.  What is supposed to be the hostname and domain name? Do I have to use the mx record domain?  I created an Extra A record for my domain. It is something like gfserver1.domain.com   I was thinking to use that as the hostname. Then domain flat out domain.com. So I have to assigned them or do I need to use a variable? This won't be the domains that postfix will use as the domain names for he address? For example from above like this: bob@gfserver1.domain.com it won't be like that correct? Like the user bob won't be using the hostname as the destination? Would if so then would I have to assign a variable to that config line? That way the domains will be variable based on requested or sent e-mails to my server?


----------



## hockey97 (Oct 9, 2011)

What should go in these variables? 


```
myhostname = host.domain.tld

mydomain = domain.tld
```

?


----------



## Abriel (Oct 9, 2011)

i have in postfix

```
mydomain = domain.tld
myhostname = $mydomain
```


----------



## Abriel (Oct 9, 2011)

Did you check 

```
/var/log/maillog
```
for any errors

```
postfix check
```
 will  be good too.


----------



## hockey97 (Oct 9, 2011)

Abriel said:
			
		

> Did you check
> 
> ```
> /var/log/maillog
> ...





			
				Abriel said:
			
		

> i have in postfix
> 
> ```
> mydomain = domain.tld
> ...



Thanks, I just tested my mail server and it still dosen't work at all. I tried using telnet using localhost with the port 25 and I can't log into the mail server. I followed all the tutorials on this page. The link provided about the mysql tables I followed everything of that but didn't do that backup domain in the domains table but part of that mysql map config the relay_domains map. I didn't create the backupmx field. So in that sql code in the mysql map I got rid of that part where it checks for the field to make sure it's equal to 1.

I am clueless as to why it's not working. In the domain table I have the domain like this: mail.domain.com  that is the mx record domain I made for my domain name at my domain provider company's servers. Here is all the tutorials I followed and did everything exactly how they did it:

http://www.purplehat.org/?page_id=8   this for postfix config
http://www.purplehat.org/?page_id=7 : used this for Dovecot config/setup
http://www.freebsdonline.com/content/view/339/348/ : followed this to make my mysql tables. I only created the tables that the purplehat.org page id 8 had in their mysql maps the queries. 

Here is what I followed from the freebsdonline.com tutorial:

```
CREATE TABLE alias
```


----------



## hockey97 (Oct 9, 2011)

Abriel said:
			
		

> Did you check
> 
> ```
> /var/log/maillog
> ...



I tried them. The maillog has 0 kb stored in the file. It shows nothing.

when I type that command I see nothing happening. Prints out nothing to the screen.


----------



## Abriel (Oct 9, 2011)

```
postfix status
```
?


----------



## hockey97 (Oct 9, 2011)

Abriel said:
			
		

> ```
> postfix status
> ```
> ?



I tried that command and get this:


```
postfix/postfix-script: the Postfix mail system is running: PID: 44711
```


----------



## Abriel (Oct 9, 2011)

postfix is working, lets check if it allow connect:

```
telnet 127.0.0.1 25
```
and type 
	
	



```
ehlo testmail.org
```


----------



## hockey97 (Oct 9, 2011)

Abriel said:
			
		

> postfix is working, lets check if it allow connect:
> 
> ```
> telnet 127.0.0.1 25
> ...



ok, tried it and this is what I got:


```
user# telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
ehlo testmail.org
Connection closed by foreign host.
```


----------



## Abriel (Oct 9, 2011)

It looks, like you have something missconfigured. I don't have postfix with mysql. I think you should first try setup postfx without mysql, and after everything will be alright add configuration to mysql.

And here is setup for mysql http://www.purplehat.org/?page_id=11


----------



## hockey97 (Oct 13, 2011)

Abriel said:
			
		

> It looks, like you have something missconfigured. I don't have postfix with mysql. I think you should first try setup postfx without mysql, and after everything will be alright add configuration to mysql.
> 
> And here is setup for mysql http://www.purplehat.org/?page_id=11



I think your right. I just restarted my computer/server and now see errors in my mailog log.

it shows this:


```
Oct 12 00:00:00 hostname newsyslog[72979]: logfile turned over
Oct 12 00:00:04 hostname postfix/proxymap[70318]: warning: mysql query failed: Table 'Mail.domain' doesn't exist
Oct 12 00:00:04 hostname postfix/trivial-rewrite[72996]: fatal: proxy:mysql:/usr/local/etc/postfix/mysql_relay_domains_maps.cf(0,lock|fold_fix): table lookup problem
Oct 12 00:00:05 hostname postfix/qmgr[72218]: warning: problem talking to service rewrite: Unknown error: 0
Oct 12 00:00:05 hostname postfix/master[1123]: warning: process /usr/local/libexec/postfix/trivial-rewrite pid 72996 exit status 1
Oct 12 00:00:05 hostname postfix/master[1123]: warning: /usr/local/libexec/postfix/trivial-rewrite: bad command startup -- throttling
Oct 12 00:01:05 hostname postfix/proxymap[70318]: warning: mysql query failed: Table 'Mail.domain' doesn't exist
Oct 12 00:01:05 hostname postfix/trivial-rewrite[73050]: fatal: proxy:mysql:/usr/local/etc/postfix/mysql_relay_domains_maps.cf(0,lock|fold_fix): table lookup problem
Oct 12 00:01:06 hostname postfix/qmgr[72218]: warning: problem talking to service rewrite: Unknown error: 0
Oct 12 00:01:06 hostname postfix/master[1123]: warning: process /usr/local/libexec/postfix/trivial-rewrite pid 73050 exit status 1
Oct 12 00:01:06 hostname postfix/master[1123]: warning: /usr/local/libexec/postfix/trivial-rewrite: bad command startup -- throttling
Oct 12 00:02:06 hostname postfix/proxymap[70318]: warning: mysql query failed: Table 'Mail.domain' doesn't exist
Oct 12 00:02:06 hostname postfix/trivial-rewrite[73102]: fatal: proxy:mysql:/usr/local/etc/postfix/mysql_relay_domains_maps.cf(0,lock|fold_fix): table lookup problem
Oct 12 00:02:07 hostname postfix/qmgr[72218]: warning: problem talking to service rewrite: Unknown error: 0
Oct 12 00:02:07 hostname postfix/master[1123]: warning: process /usr/local/libexec/postfix/trivial-rewrite pid 73102 exit status 1
Oct 12 00:02:07 hostname postfix/master[1123]: warning: /usr/local/libexec/postfix/trivial-rewrite: bad command startup -- throttling
Oct 12 00:03:07 hostname postfix/proxymap[70318]: warning: mysql query failed: Table 'Mail.domain' doesn't exist
Oct 12 00:03:07 hostname postfix/trivial-rewrite[73153]: fatal: proxy:mysql:/usr/local/etc/postfix/mysql_relay_domains_maps.cf(0,lock|fold_fix): table lookup problem
Oct 12 00:03:08 hostname postfix/qmgr[72218]: warning: problem talking to service rewrite: Unknown error: 0
Oct 12 00:03:08 hostname postfix/master[1123]: warning: process /usr/local/libexec/postfix/trivial-rewrite pid 73153 exit status 1
Oct 12 00:03:08 hostname postfix/master[1123]: warning: /usr/local/libexec/postfix/trivial-rewrite: bad command startup -- throttling
Oct 12 00:03:28 hostname postfix/qmgr[72218]: fatal: watchdog timeout
Oct 12 00:03:29 hostname postfix/master[1123]: warning: process /usr/local/libexec/postfix/qmgr pid 72218 exit status 1
Oct 12 00:03:29 hostname postfix/qmgr[73171]: 83FD3F0102C: from=<root@localhost.localhost>, size=3297, nrcpt=1 (queue active)
Oct 12 00:04:08 hostname postfix/proxymap[70318]: warning: mysql query failed: Table 'Mail.domain' doesn't exist
Oct 12 00:04:08 hostname postfix/trivial-rewrite[73204]: fatal: proxy:mysql:/usr/local/etc/postfix/mysql_relay_domains_maps.cf(0,lock|fold_fix): table lookup problem
```

the weird thing is that I can actually see the database and the fields and they do exist.


----------



## hockey97 (Oct 13, 2011)

I found out the problem one mysql map used domain as the table when it should be domains.

seems like everything works now. I sent a test e-mail to an aol account but I now get an aol error 421 which I looked up shows that I failed to have a reverse dns record. How do I make a reverse DNS record?

It looks like that my mysql tables has the wrong information inside them.


----------



## hockey97 (Oct 14, 2011)

I tested the e-mail. I can send e-mails to my AOL e-mail account but when I reply I can't received the e-mails to my postfix system. I get some error saying my e-mail system is refusing to deliver the mail.


----------



## Abriel (Oct 14, 2011)

What do you have in logs?


----------



## hockey97 (Oct 15, 2011)

Abriel said:
			
		

> What do you have in logs?



right now this is what I have in the logs. seems like the mail from my aol account got denied to send the e-mail to my posftfix mail server due to ssl. maybe it needed to login in order for the mail to be sent or something...???

here is what is inside the logs currently the maillog file:


```
Oct 14 00:00:00 dpserver1 newsyslog[5253]: logfile turned over
Oct 14 00:38:33 dpserver1 postfix/smtpd[5432]: connect from imr-da03.mx.aol.com[205.188.105.145]
Oct 14 00:39:33 dpserver1 postfix/smtpd[5432]: SSL_accept error from imr-da03.mx.aol.com[205.188.105.145]: -1
Oct 14 00:39:33 dpserver1 postfix/smtpd[5432]: lost connection after CONNECT from imr-da03.mx.aol.com[205.188.105.145]
Oct 14 00:39:33 dpserver1 postfix/smtpd[5432]: disconnect from imr-da03.mx.aol.com[205.188.105.145]
Oct 14 00:44:38 dpserver1 postfix/smtpd[5454]: connect from imr-da03.mx.aol.com[205.188.105.145]
Oct 14 00:45:38 dpserver1 postfix/smtpd[5454]: SSL_accept error from imr-da03.mx.aol.com[205.188.105.145]: -1
Oct 14 00:45:38 dpserver1 postfix/smtpd[5454]: lost connection after CONNECT from imr-da03.mx.aol.com[205.188.105.145]
Oct 14 00:45:38 dpserver1 postfix/smtpd[5454]: disconnect from imr-da03.mx.aol.com[205.188.105.145]
Oct 14 00:50:48 dpserver1 postfix/smtpd[5467]: connect from imr-da03.mx.aol.com[205.188.105.145]
Oct 14 00:51:48 dpserver1 postfix/smtpd[5467]: SSL_accept error from imr-da03.mx.aol.com[205.188.105.145]: -1
Oct 14 00:51:48 dpserver1 postfix/smtpd[5467]: lost connection after CONNECT from imr-da03.mx.aol.com[205.188.105.145]
Oct 14 00:51:48 dpserver1 postfix/smtpd[5467]: disconnect from imr-da03.mx.aol.com[205.188.105.145]
Oct 14 00:56:53 dpserver1 postfix/smtpd[5489]: connect from imr-da03.mx.aol.com[205.188.105.145]
Oct 14 00:57:53 dpserver1 postfix/smtpd[5489]: SSL_accept error from imr-da03.mx.aol.com[205.188.105.145]: -1
Oct 14 00:57:53 dpserver1 postfix/smtpd[5489]: lost connection after CONNECT from imr-da03.mx.aol.com[205.188.105.145]
Oct 14 00:57:53 dpserver1 postfix/smtpd[5489]: disconnect from imr-da03.mx.aol.com[205.188.105.145]
Oct 14 01:02:53 dpserver1 postfix/smtpd[5516]: connect from imr-da03.mx.aol.com[205.188.105.145]
Oct 14 01:03:53 dpserver1 postfix/smtpd[5516]: SSL_accept error from imr-da03.mx.aol.com[205.188.105.145]: -1
Oct 14 01:03:53 dpserver1 postfix/smtpd[5516]: lost connection after CONNECT from imr-da03.mx.aol.com[205.188.105.145]
Oct 14 01:03:53 dpserver1 postfix/smtpd[5516]: disconnect from imr-da03.mx.aol.com[205.188.105.145]
Oct 14 01:08:53 dpserver1 postfix/smtpd[5526]: connect from imr-da03.mx.aol.com[205.188.105.145]
Oct 14 01:09:53 dpserver1 postfix/smtpd[5526]: SSL_accept error from imr-da03.mx.aol.com[205.188.105.145]: -1
Oct 14 01:09:53 dpserver1 postfix/smtpd[5526]: lost connection after CONNECT from imr-da03.mx.aol.com[205.188.105.145]
Oct 14 01:09:53 dpserver1 postfix/smtpd[5526]: disconnect from imr-da03.mx.aol.com[205.188.105.145]
Oct 14 01:14:58 dpserver1 postfix/smtpd[5548]: connect from imr-da03.mx.aol.com[205.188.105.145]
```

what does the errors mean?


----------



## hockey97 (Oct 16, 2011)

I am still getting the same errors. I am trying to send e-mail from my aol account to my e-mail address on my server. it's failing due to ssl errors.  I don't understand what is wrong? I can send e-mails perfectly from my server to aol's server. There is no problem anymore before it used to be refused by AOL due to error 443 which was that the reverse domain name didn't match  or something. The mail still dosen't get sent quickly. It still does get refused but after 2 hours the e-mail gets accepted or sent to the aol mail account. I then reply to that e-mail and so far getting errors. I can't send a response back to the e-mail address.

I am trying to use myql for the data lookup tables. I am using webmin to send the e-mails. webmin still shows the default mail accounts that was already made with postfix by default which are the mail users of each group or user created my on linux system. so like www, postfix, root, etc all these users including my own user that I use to login to my freebsd 8.1 computer/server have a mailbox. yet, I config and setup postfix to use ssl, and mysql for the lookup tables. I think the data I put in the lookup tables are not correct. so, I need some tutorials to explain what needs to be inside the mysql tables? 

like for me I have mydomain.com and a mx record with it as mail.mydomain.com  I have it in that way. so in mysql I put domain as mail.mydomain.com. my host name is domainserver1.mydomain.com  that is my computers hostname. for some reason when I send the e-mail out from my server it automatically uses the domainserver1.mydomain.com  type address. I do have the domainserver1.mydomain.com as an A record for mydomian.com 

I want to know how I can make my e-mails look like this: user@mydomain.com. I don't want it like: user@mail.mydomain.com or  user@domainserver1.mydomain.com. I want it like: user@mydomain.com. how to get it like that? 

I seen the tutorials posted on here so far. I made the mysql tables following the tutorials and also just reading the postfix-mysql mappings sql code. I would create the tables and fields based off the sql code. now I am clueless as to what should be stored in those tables. I never found any tutorials that gave good examples and explanation as to what is the purpose of those tables and what is needed. This is my first postfix setup. I been trying to set one up in the past 3 years. I always failed. If I used the default settings using the postfix maps. I would have a working mail server. I was able to send and receive e-mails. but, I don't want it like that. I want to use mysql. I want to eventually make my own web mail interface like an e-mail service. 

I know php so I thought if I can get the maps using mysql. I can easily make a web interface to delete e-mails etc as long I know where each users mailbox is located and php has access to those mail boxes.


----------



## Abriel (Oct 16, 2011)

Paste

```
cat /usr/local/etc/postfix/main.cf
```
and

```
postconf
```
But as said, i have only postfix without mysql.


----------



## hockey97 (Oct 16, 2011)

Abriel said:
			
		

> Paste
> 
> ```
> cat /usr/local/etc/postfix/main.cf
> ...



ok, I did those code. It gives me a list of variables and their values assigned to them.

do you want me to post them here?


----------



## Abriel (Oct 17, 2011)

Would be nice.


----------



## hockey97 (Oct 19, 2011)

Abriel said:
			
		

> Would be nice.



OK, here is what it prints out to screen: Click here for the printout variables

It was too long for this website had to paste the printout to some other website. What could be the problem? I can send e-mail to an aol account but can't receive an e-mail from the aol user. Looks like an SSL error. Something where password and user weren't matched or something like that.

How to fix those errors?


----------



## Abriel (Oct 19, 2011)

Show me /usr/local/etc/postfix/main.cf and /usr/local/etc/postfix/master.cf and
[cmd=]openssl s_client -connect yourdomain:465[/cmd]
Setup in /usr/local/etc/postfix/main.cf
[CMD=]smtpd_tls_loglevel = 2[/CMD]


----------



## hockey97 (Oct 21, 2011)

Abriel said:
			
		

> Show me /usr/local/etc/postfix/main.cf and /usr/local/etc/postfix/master.cf and
> [cmd=]openssl s_client -connect yourdomain:465[/cmd]
> Setup in /usr/local/etc/postfix/main.cf
> [CMD=]smtpd_tls_loglevel = 2[/CMD]



ok, I will pm you that information. Well I will post it to another website but will give you the links. Hold up let me get that information.


----------



## Abriel (Oct 24, 2011)

The main problem was, that you need install and set up security/cyrus-sasl2 and some minor mistakes in main.conf, master.conf and dovecot.conf. And if you are using http://www.purplehat.org/?page_id=16 guide remember about cyrus-sasl2.


----------



## ph0enix (Oct 25, 2011)

hockey97 said:
			
		

> How do I make a reverse DNS record?



Usually you have to ask your ISP to do that for you unless they've delegated the IP addresses you're assigning to you.  Then you can just create a reverse/PTR record matching the hostname in the responsible DNS server.


----------



## hockey97 (Nov 3, 2011)

ph0enix said:
			
		

> Usually you have to ask your ISP to do that for you unless they've delegated the IP addresses you're assigning to you.  Then you can just create a reverse/PTR record matching the hostname in the responsible DNS server.



I pay $5 extra to have a static Ip address. however the people there aren't very technical because it took me  10 days to have then understand what a static ip address. I had to explain it to them and they had to figure out if they offer it.

So I hope when I ask they actually understand what I am asking for.


----------



## hurricane_sh (Nov 3, 2011)

On a side note, why don't you use Google App for email service? They do everything for you for free. I can't see any advantages to setup own email server over Google App.


----------



## hockey97 (Nov 4, 2011)

hurricane_sh said:
			
		

> On a side note, why don't you use Google App for email service? They do everything for you for free. I can't see any advantages to setup own email server over Google App.



I might as well take windows 7 look at the sources of it. take out all the artwork and replace it with mine and call it my own OS. 

What your suggesting to me is illegal. I am trying to use it for commercial purposes and for me to use google I would have to pay a fee for it plus no one will use my services if they know I am using Google services why would others use mine if they can go directly to the source and use Google services.


----------



## hurricane_sh (Nov 4, 2011)

I see, just wanted to let you know about Google App in cased you weren't aware of it, no offense intended. Obviously you are a pro and know what you are doing. I'm just a newbie and always try to avoid configuring a service if I could.


----------

