Вход на сайт
Яндекс.Метрика

Рейтинг@Mail.ru

Настройка Exim

Описание настройки связки "Exim + MySQL +Courier-Imap"

 Ставим exim с поддержкой mysql

#cd /usr/ports/mail/exim-mysql

#make && make install && make clean

Создаём базу и таблицы для работы сервиса exim по прилагаемым дампам

mysql>CREATE DATABASE exim;

Дамп базы с таблицами в exim сохраним в файле /usr/local/etc/exim/exim.sql:

-- MySQL dump 10.13 Distrib 6.0.11-alpha, for portbld-freebsd8.0 (i386)

--

-- Host: localhost Database: exim

-- ------------------------------------------------------

-- Server version 6.0.11-alpha

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;

/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;

/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;

/*!40101 SET NAMES utf8 */;

/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;

/*!40103 SET TIME_ZONE='+00:00' */;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;

/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;

/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;

/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--

-- Table structure for table `aliases`

--

DROP TABLE IF EXISTS `aliases`;

/*!40101 SET @saved_cs_client = @@character_set_client */;

/*!40101 SET character_set_client = utf8 */;

CREATE TABLE `aliases` (

`to_user` varchar(128) NOT NULL DEFAULT '',

`recipients` text,

PRIMARY KEY (`to_user`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*!40101 SET character_set_client = @saved_cs_client */;

--

-- Dumping data for table `aliases`

--

LOCK TABLES `aliases` WRITE;

/*!40000 ALTER TABLE `aliases` DISABLE KEYS */;

INSERT INTO `aliases` VALUES ('admin@exim.local','serge@exim.local');

/*!40000 ALTER TABLE `aliases` ENABLE KEYS */;

UNLOCK TABLES;

--

-- Table structure for table `domains`

--

DROP TABLE IF EXISTS `domains`;

/*!40101 SET @saved_cs_client = @@character_set_client */;

/*!40101 SET character_set_client = utf8 */;

CREATE TABLE `domains` (

`domainname` varchar(128) NOT NULL DEFAULT '',

`type` enum('LOCAL','RELAY','VIRTUAL') DEFAULT 'LOCAL',

PRIMARY KEY (`domainname`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*!40101 SET character_set_client = @saved_cs_client */;

--

-- Dumping data for table `domains`

--

LOCK TABLES `domains` WRITE;

/*!40000 ALTER TABLE `domains` DISABLE KEYS */;

INSERT INTO `domains` VALUES ('exim.local','LOCAL'),('local','LOCAL'),('exim','LOCAL');

/*!40000 ALTER TABLE `domains` ENABLE KEYS */;

UNLOCK TABLES;

--

-- Table structure for table `users`

--

DROP TABLE IF EXISTS `users`;

/*!40101 SET @saved_cs_client = @@character_set_client */;

/*!40101 SET character_set_client = utf8 */;

CREATE TABLE `users` (

`id` varchar(64) NOT NULL DEFAULT '',

`full_name` varchar(128) NOT NULL DEFAULT '',

`passwd` varchar(64) NOT NULL DEFAULT '',

`uid` int(5) unsigned DEFAULT '26',

`gid` int(5) unsigned DEFAULT '26',

`home` varchar(128) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT '/var/mail/exim/',

`active` enum('Y','N') DEFAULT 'Y',

PRIMARY KEY (`id`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1;

/*!40101 SET character_set_client = @saved_cs_client */;

--

-- Dumping data for table `users`

--

LOCK TABLES `users` WRITE;

/*!40000 ALTER TABLE `users` DISABLE KEYS */;

INSERT INTO `users` VALUES ('skuleshov@exim.local','eto Ja','1234567',26,26,'/var/mail/exim/','Y'),('skuleshov@local','JA','1234567',26,26,'/var/mail/exim/','Y'),('skuleshov@exim','JA','1234567',26,26,'/var/mail/exim/','Y'),('serega@local','JA','1234567',26,26,'/var/mail/exim/','Y');

/*!40000 ALTER TABLE `users` ENABLE KEYS */;

UNLOCK TABLES;

/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;

/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;

/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;

/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2010-10-13 20:31:54

 Создаем наши таблички в базе:

mysql>mysql -hlocalhost -utoot -ppassword exim < exim.sql

 Создаем пользователя sqlmail и присваиваем ему полные права на базу exim:

mysql>GRANT ALL PRIVILEGES ON exim.* TO exim@localhost IDENTIFIED BY 'exim' WITH GRANT OPTION;


После чего редактируем конфиг exim - /usr/local/etc/exim/configure:

primary_hostname = exim.local

hide mysql_servers = localhost/exim/exim/exim

domainlist local_domains = ${lookup mysql{SELECT domainname FROM domains WHERE domainname='${domain}' AND (type='LOCAL' OR type='VIRTUAL')}}

domainlist relay_to_domains = ${lookup mysql{SELECT domainname FROM domains WHERE domainname='${domain}' AND type='RELAY'}}

hostlist relay_from_hosts = localhost : 127.0.0.1 : 192.168.0.0/24 : 10.0.2.15

acl_smtp_rcpt = acl_check_rcpt

acl_smtp_data = acl_check_data

qualify_domain = local

allow_domain_literals = false

exim_user = mailnull

exim_group = mail

#never_users =

host_lookup = *

rfc1413_hosts = *

rfc1413_query_timeout = 5s

ignore_bounce_errors_after = 2d

timeout_frozen_after = 7d

begin acl

acl_check_rcpt:

accept hosts = :

deny message = Restricted characters in address

domains = +local_domains

local_parts = ^[.] : ^.*[@%!/|]

deny message = Restricted characters in address

domains = !+local_domains

local_parts = ^[./|] : ^.*[@%!] : ^.*/\\.\\./

accept domains = +local_domains

endpass

message ="Tut net takogo"

verify = recipient

accept domains = +relay_to_domains

endpass

message = unknown user

verify = recipient

accept hosts = +relay_from_hosts

# control = submission

accept authenticated = *

# control = submission

accept

acl_check_data:

accept

begin routers

dnslookup:

driver = dnslookup

domains = ! +local_domains

transport = remote_smtp

ignore_target_hosts = 0.0.0.0 : 127.0.0.0/8 : 10.0.2.15

no_more

system_aliases:

driver = redirect

allow_fail

allow_defer

data = ${lookup{$local_part}lsearch{/etc/aliases}}

user = mailnull

group = mail

file_transport = address_file

pipe_transport = address_pipe

userforward:

driver = redirect

check_local_user

# local_part_suffix = +* : -*

# local_part_suffix_optional

file = $home/.forward

# allow_filter

no_verify

no_expn

check_ancestor

file_transport = address_file

pipe_transport = address_pipe

reply_transport = address_reply

condition = ${if exists{$home/.forward} {yes} {no} }

mysqluser:

driver = accept

condition = ${if eq{} {${lookup mysql{SELECT home FROM users WHERE id='${quote_mysql:$local_part@$domain}' OR id='${quote_mysql:@$domain}'}}}{no}{yes}}

transport = mysql_delivery

 

#localuser:

# driver = accept

# check_local_user

# local_part_suffix = +* : -*

# local_part_suffix_optional

# transport = local_delivery

# cannot_route_message = Unknown user

begin transports

remote_smtp:

driver = smtp

mysql_delivery:

driver = appendfile

check_string = ""

create_directory

delivery_date_add

directory = ${lookup mysql{SELECT CONCAT(home, '${local_part}@${domain}') FROM users WHERE id='${local_part}@${domain}'}}

directory_mode = 770

envelope_to_add

group = mail

maildir_format

maildir_tag = ,S=$message_size

message_prefix = ""

message_suffix = ""

mode = 0600

#local_delivery:

# driver = appendfile

# file = /var/mail/$local_part

# delivery_date_add

# envelope_to_add

# return_path_add

# group = mail

# user = $local_part

# mode = 0660

# no_mode_fail_narrower

address_pipe:

driver = pipe

return_output

address_file:

driver = appendfile

delivery_date_add

envelope_to_add

return_path_add

address_reply:

driver = autoreply

begin authenticators

auth_plain:

driver = plaintext

public_name = PLAIN

server_condition = ${lookup mysql{SELECT id FROM users \

WHERE id = '${quote_mysql:$1}' \

AND passwd = '${quote_mysql:$2}' \

AND active ='Y'}{yes}{no}}

server_prompts = :

server_set_id = $2

auth_login:

driver = plaintext

public_name = LOGIN

server_condition = ${lookup mysql{SELECT id FROM users \

WHERE id = '${quote_mysql:$1}' \

AND passwd = '${quote_mysql:$2}' \

AND active = 'Y'}{yes}{no}}

server_prompts = Username:: : Password::

server_set_id = $1

auth_cram_md5:

driver = cram_md5

public_name = CRAM-MD5

server_secret = ${lookup mysql{SELECT passwd FROM users \

WHERE id = '${quote_mysql:$1}' \

AND active = 'Y'}{$value}fail}

server_set_id = $1

 

# End of Exim configuration file

 Проверим корректность конфига командой exim -bV.

Если нет ошибок - то продолжаем, если есть - исправлям.

Добавляем в /etc/rc.conf строку exim_enable="YES" и sendmail_enable="NONE"(не использовать sendmail), после чего стартуем exim:

#/usr/local/etc/rc.d/exim start

Теперь сервер готов принимать почту. Для проверки можно отправить самому себе письмо с консоли:

#mail -s test_e_mail skuleshov@local < /usr/local/etc/exim/configure

После чего надо идем в папку /var/mail/exim и смотрим наличие внутри папки с именем пользователя, а в ней файл письма в папке NEW. Если всё нормально - идём дальше, нет - смотрим логи - /var/log/exim/maillog и устраняем ошибки.

Теперь осталось научить его отдавать почту клиентам. Для этого ставим courier-imap:

#cd /usr/ports/mail/courier-imap

#make && make install && make clean

В появившемся окошке с опциями нам нужно только одно - поддержка авторизации MySQL. По окончании настройки настраиваем, но не сам courier-imap, a courier-authlib которого он за собой тащит при установке.

Редактируем файл /usr/local/etc/authlib/authmysqlrc. Должно получится так:

MYSQL_SERVER localhost

MYSQL_USERNAME exim

MYSQL_PASSWORD exim

MYSQL_PORT 3306

MYSQL_DATABASE exim

MYSQL_USER_TABLE `users`

MYSQL_CLEAR_PWFIELD `passwd`

MYSQL_UID_FIELD 26

MYSQL_GID_FIELD 26

MYSQL_LOGIN_FIELD `id`

MYSQL_NAME_FIELD `full_name`

MYSQL_MAILDIR_FIELD CONCAT('/var/mail/exim/', `id`)

DEFAULT_DOMAIN local

После чего добавляем следующие строки в /etc/rc.conf для запуска imap и pop:

courier_imap_pop3d_enable="YES"

courier_imap_imapd_enable="YES"

courier_authdaemond_enable="YES"

 И запускаем службы:

#cd /usr/local/etc/rc.d

#./courier-authdaemond start

#./courier-imap-imapd start

#./courier-imap-pop3d start

Всё, готово.

 

unix-way