Настройка mail-proxy

MKG nginx-forum at nginx.us
Thu Oct 18 08:23:33 UTC 2012


Хочу настроить mail-proxy для почты яндекса.
Сделал так (делаю пока под win2k3):



Файл nginx.conf
-----------------------------------------------------


worker_processes  1;

error_log  logs/error.log;


events {
    worker_connections  1024;
}






http {
    
    include       mime.types;
    default_type  application/octet-stream;
    
    
    upstream auth_backend {
        server 127.0.0.1:55680;
        server 127.0.0.1:55681;
    }
    
    
    
    server {
        
        listen 80 default;
        server_name localhost;
        
        server_tokens off;
        
        access_log logs/access.log;
        
        location / {
            root public_html;
            index index.html index.htm index.php;
        }
        
        location ~ \.php$ {
            
            root public_html;
            
            fastcgi_connect_timeout 1;
            fastcgi_next_upstream timeout;
            fastcgi_pass auth_backend;
            fastcgi_param  SCRIPT_FILENAME   
$document_root$fastcgi_script_name;
            
            
            include fastcgi_params;
        }
        
        location ~ /\.ht {
            deny all;
        }
        
        
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;
        }
        
    }
}










mail {

    server_name mail.example.com;
    auth_http 127.0.0.1:16843/mail_auth.php;
    
    proxy on;
    
    
    pop3_auth         plain apop cram-md5;
    pop3_capabilities "LAST" "TOP" "USER" "PIPELINING" "UIDL";
    
    
    server {
        listen 110;
        protocol pop3;
        proxy_pass_error_message on;
    }
    
    
    xclient           on;
    
    server {
        listen 25;
        protocol smtp;
    }
    
}

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




Файл mail_auth.php
-----------------------------------------------------
<?php


ob_start();

$Was_Error = true;
$Error_Str = '';



if (isset($_SERVER['HTTP_AUTH_USER'])) { $User_Name =
strtolower($_SERVER['HTTP_AUTH_USER']); } else { $User_Name = NULL; }
if (isset($_SERVER['HTTP_AUTH_PASS'])) { $User_Pass =
$_SERVER['HTTP_AUTH_PASS']; } else { $User_Pass = NULL; }
if (isset($_SERVER['HTTP_AUTH_PROTOCOL'])) { $Protocol =
strtolower($_SERVER['HTTP_AUTH_PROTOCOL']); } else { $Protocol = NULL; }
if (isset($_SERVER['HTTP_CLIENT_IP'])) { $Client_IP =
$_SERVER['HTTP_CLIENT_IP']; } else { $Client_IP = NULL; }



$Mail_Server_Port = NULL;
if ($Protocol == 'smtp') { $Mail_Server_Port = 25; }
elseif ($Protocol == 'pop3') { $Mail_Server_Port = 110; }
else { /* ошибка - протокол не поддерживается*/ }






$Mail_Add_Arr = explode('@', $User_Name, 2);

if (isset($Mail_Add_Arr[0])) { $User_Mailbox_Part =
strtolower($Mail_Add_Arr[0]); } else { $User_Mailbox_Part = NULL; }
if (isset($Mail_Add_Arr[1])) { $Mail_Server_Part  =
strtolower($Mail_Add_Arr[1]); } else { $Mail_Server_Part = NULL; }



$Mail_Server = NULL;

if ($Protocol == 'smtp') {
    if ($Mail_Server_Part == 'yandex.ru') {
        $Mail_Server = 'smtp.yandex.ru';
    }
}
elseif ($Protocol == 'pop3') {
    if ($Mail_Server_Part == 'yandex.ru') {
        $Mail_Server = 'pop.yandex.ru';
    }
}




if (isset($Mail_Server)) {
    
    $Mail_Server_IPs = gethostbynamel($Mail_Server);
    if ($Mail_Server_IPs) {
        
        $Mail_Server_IP_Count = count($Mail_Server_IPs);
        if ($Mail_Server_IP_Count > 0) {
            
            $idx = mt_rand(0, $Mail_Server_IP_Count - 1);
            $Mail_Server_IP = $Mail_Server_IPs[$idx];
            
            $Was_Error = false;
            
        }
        else {
            /* ошибка */
        }
        
    }
    else {
        /* ошибка */
    }
    
}
else {
    /* ошибка */
}




header("Status: 200 OK");

if (!$Was_Error) {
    
    header('Auth-Status: OK');
    header('Auth-Server: ' . $Mail_Server_IP);
    header('Auth-Port: ' . $Mail_Server_Port);
    header('Auth-User: ' . $User_Name);
    header('Auth-Pass: ' . $User_Pass);
    
}
else {
    
    header('Auth-Status: ' . $Error_Str);
    header('Auth-Wait: 3');
    
}


ob_end_flush();


?>
-----------------------------------------------------




По POP3 почта принимается нормально, а отправка по SMTP не работает.

Bat пишет:
-----------------------------------------------------
FETCH - Соединение с сервером прервано (последние переданные команды: "EHLO
localhost", "MAIL FROM:<.............. at yandex.ru> SIZE=468")
-----------------------------------------------------

В error.log появляется такая строчка:
-----------------------------------------------------
 [error] 8324#11272: *6 upstream sent invalid response: "502 5.5.2 Syntax
error, command unrecognized." while reading response from upstream, client:
127.0.0.1, server: 0.0.0.0:25, login: "........... at yandex.ru", upstream:
213.180.204.38:25
-----------------------------------------------------


Подскажите пожалуйста как правильно настроить SMTP-proxy

Posted at Nginx Forum: http://forum.nginx.org/read.php?21,231945,231945#msg-231945



Подробная информация о списке рассылки nginx-ru