2014-04-10 7 views
0

사실은 후위 문제가 아니므로 stackoverflow에서 다시 게시해야한다고 들었습니다. 그러나, 나는 PHP 접미사 상호 작용에 대해 충분히 알지 못한다. 따라서 스크립트 부분에 문제가 있고 누군가가 그것을 볼 수 있다면 알려줘. 메일을 전달할 특별한 방법이 있다면 정상적으로 수행해야합니다. 한 번 스크립트를 통과하면 문제가 발생합니다. 고맙습니다!접미사 : 반송 확인. 전자 메일은 PHP로 파이프되어 있지만 전자 메일이 제대로 보내고받을 수 없습니다.

- 내가 일하는 것처럼

, 나는 나중에 사용하기 위해, 내가 무엇을하고 있었는지의 안내를했다. 나는 이것을 약간의 시간 동안 일하도록 얻으려고 노력해 왔고 나는 이메일을 스크립트를 통과하도록했다. 수신 된 모든 메일 (반송 된 메일 또는 기타)은받은 후 메일 박스에 저장되지 않고 스크립트 실행이 완료됩니다. 스크립트가 실행되고 오류없이 종료됩니다. 추가 할 수도 있습니다.

  1. 추가 디렉토리 :/usr/지방/bouncehandler에 $ sudo를에서 mkdir/usr/지방/bouncehandler

  2. 추가 스크립트 파일 : mybh.php

  3. 스크립트의 실행을 허용 : 는 chmod A + X mybh.php

  4. 추가 사용자 : $ sudo를이 반송은 useradd

  5. (작성은/etc/후위/virtual_aliases 포괄 별칭 추가 - 기존 로컬 사용자 수 있어야 localuser : [email protected] 루트 : 이 모든 단계가 제거

  6. 전송 매핑을 추가하기 위해/etc/postfix/transport를 만듭니다. "mytransportname"은 원하는대로 지정할 수 있습니다. 그것은 master.cf 이하에 사용되는 : mydomain.com mybh : ($ sudo는 postmap은/etc/후위/virtual_aliases) 제거 $ :

  7. 다음, 운송 및 virtual_aliases 모두 DB 파일로 컴파일 할 필요가 sudo는 postmap은/etc/포스트 픽스/운송 /etc/postfix/master.cf에

  8. 변경 : N 의 SMTP INET - - - - smtpd를 : 을 제거 (-o content_filter mybh = 거짓)

  9. /etc/postfix/master.cf에 전송을 추가합니다. mybh unix - nn-10 pipe flags = q 사용자 = 반송 argv =/usr/local/bouncehandler/mybh.php $ {수신자} $ {수신자}

    /etc/postfix/master.cf에
  10. 변경 :

    픽업 FIFO 없음 - - 60 1 픽업 (-o content_filter = mybh : 더미)은

  11. 제거에는은/etc/포스트 픽스 /본관.CF :

transport_maps = 해시 :은/etc/후위/전송 (virtual_alias_maps = 해시 :은/etc/후위/virtual_aliases)) 삭제됨

  1. 연결 데이터베이스로 만들고 테이블 bounce_list : NOT이 bounce_list있는 경우

    테이블 만들기 ( 이메일 VARCHAR (255) NOT NULL PRIMARY KEY, bounce_count의 INT (4) NOT N ULL ) ENGINE = InnoDB;

  2. 다시 시작 후위 :

$ sudo는 접미사를 다시로드

수신자가 나는 그것이 나에게 전송되는 것을 나타냅니다 믿고 내 도메인 인 경우 나 검사를 통해 전달하는 스크립트. 그렇다면 처음에 누군가 다른 사람에게 보냈는지 확인하고, 그렇다면 사용자를 확인하고 이메일이 반송 된 것으로 간주합니다. 스크립트에서 다른 작업을 수행하지 않으므로, 이후에 원래 메일 스크립트가있는 경우 어떻게 호출해야하는지 확실하지 않습니다.

mybh.php :

#!/usr/bin/php -q 
<?php 

//////////////////////////////////////////////////////// 
//Collects sender and recipient data from email pass 
//////////////////////////////////////////////////////// 
$sender = trim($argv[1]); 
$recipient = trim($argv[2]); 


$bounceProcd = FALSE; 

list($name, $domain) = explode('@', $recipient); 


if(strpos($recipient, 'mydomain.com') !== false) 
{ 

    //////////////////////////////////////////////////////// 
    //Database variable initialization 
    //////////////////////////////////////////////////////// 
    $host = "localhost"; 
    $user = "user"; 
    $pass = "password"; 
    $db = "database"; 

    //////////////////////////////////////////////////////// 
    //Establish database connection 
    //////////////////////////////////////////////////////// 
    $con = mysqli_connect($host, $user, $pass, $db); 

    //////////////////////////////////////////////////////// 
    //Verify that database is connected properly 
    //////////////////////////////////////////////////////// 
    if(!$con) 
    { 
     exit(75); 
    } 

    //////////////////////////////////////////////////////// 
    //Initialize query into variable 
    //////////////////////////////////////////////////////// 
    $query = "INSERT INTO bounce_list VALUES ('$recipient', 1) ON DUPLICATE KEY UPDATE bounce_count = bounce_count + 1"; 

    //////////////////////////////////////////////////////// 
    //Run query and store in variable 
    //////////////////////////////////////////////////////// 
    $result = mysqli_query($con, $query); 

    $bounceProcd = mysqli_affected_rows($con) > 0; 

    //////////////////////////////////////////////////////// 
    //Verify that query executed 
    //////////////////////////////////////////////////////// 
    if (!$result) { 

     $con->close(); 

     exit(75); 
    } 


    $con->close(); 

    $dataLen = IgnoreMessageData(); 
} 


$exitStatus = (TRUE == $bounceProcd) ? 0 : 75; 

//////////////////////////////////////////////////////// 
//Pass email to mailbox 
//////////////////////////////////////////////////////// 
exit($exitStatus+0); 


function IgnoreMessageData() 
{ 
    $msgLen = 0; 
    $fd = fopen('php://stdin', 'r'); 
    while (FALSE === feof($fd)) 
    { 
     $dunsel = fread($fd, 1024); 
     $msgLen += strlen($dunsel); 
    } 
    fclose($fd); 
    return $msgLen; 
} 
return; 
?> 

main.cf :

# See /usr/share/postfix/main.cf.dist for a commented, more complete 
version 
# Debian specific:  Specifying a file name will cause the first 
# line of that file to be used as the name.  The Debian default 
# is /etc/mailname. 
#myorigin = /etc/mailname 

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu) 

biff = no 

# appending .domain is the MUA's job. 
append_dot_mydomain = no 

# Uncomment the next line to generate "delayed mail" warnings 
#delay_warning_time = 4h 
readme_directory = no 

# TLS parameters 
smtpd_tls_cert_file=/etc/ssl/certs/ssl­cert­snakeoil.pem 

smtpd_tls_key_file=/etc/ssl/private/ssl­cert­snakeoil.key 

smtpd_use_tls=yes 

smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache 

smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache 

# See /usr/share/doc/postfix/TLS_README.gz in the postfix­doc package for 
# information on enabling SSL in the smtp client. 

myhostname = main.mydomain.com 

alias_maps = hash:/etc/aliases 

alias_database = hash:/etc/aliases 

smtp_generic_maps = hash:/etc/postfix/generic 

myorigin = /etc/mailname 

mydestination = admin.mydomain.com, main.mydomain.com, 
localhost.mydomain.com, localhost 

relayhost = 

mynetworks = (deleted this line) 

mailbox_size_limit = 0 

recipient_delimiter = + 

inet_interfaces = all 

transport_maps = hash:/etc/postfix/transport 

master.cf :

# 
# Postfix master process configuration file. For details on the format 
# of the file, see the master(5) manual page (command: "man 5 master"). 
# 
# Do not forget to execute "postfix reload" after editing this file. 
# 
# ========================================================================== 
# service type private unpriv chroot wakeup maxproc command + args 
#    (yes) (yes) (yes) (never) (100) 
# ========================================================================== 
smtp  inet n  -  -  -  -  smtpd 

mybh  unix -  n  n  -  -  pipe 
    flags=q user=bounce argv=/usr/local/bouncehandler/mybh.php ${sender} ${recipient} 

#smtp  inet n  -  -  -  1  postscreen 
#smtpd  pass -  -  -  -  -  smtpd 
#dnsblog unix -  -  -  -  0  dnsblog 
#tlsproxy unix -  -  -  -  0  tlsproxy 
#submission inet n  -  -  -  -  smtpd 
# -o syslog_name=postfix/submission 
# -o smtpd_tls_security_level=encrypt 
# -o smtpd_sasl_auth_enable=yes 
# -o smtpd_client_restrictions=permit_sasl_authenticated,reject 
# -o milter_macro_daemon_name=ORIGINATING 
#smtps  inet n  -  -  -  -  smtpd 
# -o syslog_name=postfix/smtps 
# -o smtpd_tls_wrappermode=yes 
# -o smtpd_sasl_auth_enable=yes 
# -o smtpd_client_restrictions=permit_sasl_authenticated,reject 
# -o milter_macro_daemon_name=ORIGINATING 
#628  inet n  -  -  -  -  qmqpd 

pickup fifo n  -  -  60  1  pickup 

cleanup unix n  -  -  -  0  cleanup 
qmgr  fifo n  -  n  300  1  qmgr 
#qmgr  fifo n  -  n  300  1  oqmgr 
tlsmgr unix -  -  -  1000? 1  tlsmgr 
rewrite unix -  -  -  -  -  trivial-rewrite 
bounce unix -  -  -  -  0  bounce 
defer  unix -  -  -  -  0  bounce 
trace  unix -  -  -  -  0  bounce 
verify unix -  -  -  -  1  verify 
flush  unix n  -  -  1000? 0  flush 
proxymap unix -  -  n  -  -  proxymap 
proxywrite unix -  -  n  -  1  proxymap 
smtp  unix -  -  -  -  -  smtp 
relay  unix -  -  -  -  -  smtp 
#  -o smtp_helo_timeout=5 -o smtp_connect_timeout=5 
showq  unix n  -  -  -  -  showq 
error  unix -  -  -  -  -  error 
retry  unix -  -  -  -  -  error 
discard unix -  -  -  -  -  discard 
local  unix -  n  n  -  -  local 
virtual unix -  n  n  -  -  virtual 
lmtp  unix -  -  -  -  -  lmtp 
anvil  unix -  -  -  -  1  anvil 
scache unix -  -  -  -  1  scache 
# 
# ==================================================================== 
# Interfaces to non-Postfix software. Be sure to examine the manual 
# pages of the non-Postfix software to find out what options it wants. 
# 
# Many of the following services use the Postfix pipe(8) delivery 
# agent. See the pipe(8) man page for information about ${recipient} 
# and other message envelope options. 
# ==================================================================== 
# 
# maildrop. See the Postfix MAILDROP_README file for details. 
# Also specify in main.cf: maildrop_destination_recipient_limit=1 
# 
maildrop unix -  n  n  -  -  pipe 
    flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient} 
# 
# ==================================================================== 
# 
# Recent Cyrus versions can use the existing "lmtp" master.cf entry. 
# 
# Specify in cyrus.conf: 
# lmtp cmd="lmtpd -a" listen="localhost:lmtp" proto=tcp4 
# 
# Specify in main.cf one or more of the following: 
# mailbox_transport = lmtp:inet:localhost 
# virtual_transport = lmtp:inet:localhost 
# 
# ==================================================================== 
# 
# Cyrus 2.1.5 (Amos Gouaux) 
# Also specify in main.cf: cyrus_destination_recipient_limit=1 
# 
#cyrus  unix -  n  n  -  -  pipe 
# user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user} 
# 
# ==================================================================== 
# Old example of delivery via Cyrus. 
# 
#old-cyrus unix -  n  n  -  -  pipe 
# flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user} 
# 
# ==================================================================== 
# 
# See the Postfix UUCP_README file for configuration details. 
# 
uucp  unix -  n  n  -  -  pipe 
    flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient) 
# 
# Other external delivery methods. 
# 
ifmail unix -  n  n  -  -  pipe 
    flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient) 
bsmtp  unix -  n  n  -  -  pipe 
    flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient 
scalemail-backend unix - n n - 2 pipe 
    flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension} 
mailman unix -  n  n  -  -  pipe 
    flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py 
    ${nexthop} ${user} 

mail.log :

사월 16 05 : 55 : 3 7 후위 서버 이름/픽업 [1,774] 48F1F2C0663 : UID = 0에서 =

사월 16 5시 55분 37초 후위 서버 이름/정리 [1,789] 48F1F2C0663 : 메시지 ID = < [email protected] .COM>

사월 16 5시 55분 37초 후위 서버 이름/QMGR [1,773] 48F1F2C0663 =로부터 크기 = 294 nrcpt = 1 (활성 큐)

사월 16 5시 55분 58초 serverName postfix/smtp [1791] : 48F1F2C0663 : to = < [email protected]>, relay = mail.digitalsanct uary.com [174.73.49.123] : 52, 지연 = 40, 지연 = 19/0.01/0.42/20, dsn = 5.1.1, 상태 = 반송 됨 (호스트 mail.digitalsanctuary.com [174.37.94.132] 550 5.1.1 < [email protected]> : 거부받는 사람 주소 : 가상 별칭 테이블에서 알 수없는 사용자)

4월 16일 5시 55분 58초 서버 이름 후위/정리 [(응답에 명령에게 RCPT합니다) 1789] : 3F13A2C0869 : message-id = < [email protected]>

사월 16 5시 55분 58초 후위 서버 이름/반송 [1,800] 48F1F2C0663 송신자 배달 통지 : 3F13A2C0869

사월 16 5시 55분 58초 후위 서버 이름/QMGR [1,773] 3F13A2C0869 : 48F1F2C0663 :

제거

사월 16 5시 55분 < => = 2,513 크기, nrcpt = 1 (활성 큐)

사월 16 5시 55분 58초 후위 서버 이름/QMGR [1773]을 행 : 58 serverName postfix/pipe [1801] : 3F13A2C0869 : to =, relay = mybh, delay = 0.04,,지연 = 0/0/0/0.03 DSN는 = 2.0.0 상태 = 전송 (mybh 서비스를 통해 제공)

사월 16 5시 55분 58초 서버 이름 후위/QMGR [1,773] 3F13A2C0869는 :

제거

나는 많은 가이드와 다른 많은 게시물을 읽으면서 보았던 필요한 정보에서 도움이 될 수 있다고 생각한 모든 정보를 포함 시켰으며이를 직접 파악하려고 노력했습니다.

신선한 눈빛이 나를 도울 수 있다면 크게 감사하겠습니다.

  • 누구든지 아이디어를 가지고 있다면, 반송 된 이메일에 원래 대상 전자 메일을 첨부하십시오.

당신에게

답변

1

감사 그래서 아직도 당신이 원래받는 사람에게 메시지를 보낼 필요가 반송 메시지를 수신하기 위해, 그래서 당신은 당신이 기본적으로 내가 여기에서 일을 처리 할 수 ​​있습니다 말을하는지 필터를 추가 할 때 .

// original bounce handling code 

// Now resend the bounced message 
// get message from stdin 
$fp = fopen("php://stdin", "r"); 

$message= ''; 
while (! feof($fp)) { 
    $message.= fgets($fp); 
} 

// send to original recipient, lazy but easiest just to pipe the message in to sendmail 
shell_exec('echo ' . escapeshellarg($message) . ' | /usr/sbin/sendmail -G -i ' . $recipient);