2013-04-27 2 views
0

헬프 데스크 응용 프로그램을 구현하려고하는데 모든 들어오고 나가는 전자 메일을 처리하기 위해 PHP 스크립트를 작성해야합니다. Postfix를 MTA로 생각할 때, 수신 메일에 대해 이렇게하는 방법을 설명하는이 게시물을 발견했습니다 : Postfix - How to process incoming emails?. 그것은 Postfix의 mailbox_command 설정을 사용하는 것이 좋으며 매력적으로 작동합니다. 나가 보내는 전자 우편을 위해 존재하는 무언가가 있는지 생각해 보는가?Postfix - 보내는 이메일을 처리하는 방법?

  • 산란기의 물고기 수컷
  • content_filter
  • recipient_bcc_maps

마지막 옵션이되는 : 스크립트에, 당신이 하나 필요를 보내는 모든 메일의 사본을 보내하기 위해

+0

1) "프로세스"란 무엇을 의미합니까? 1a) see/read 1b) rewrite 1c) ... 2) "postfix"솔루션에만 관심이 있습니까? – AnFi

+0

나는 Postfix 문서를 읽은 채로 필자가 원하는 것에 가장 근접한 기능으로'filters'를 발견했습니다. 필자의 요구 사항을 명확히하기 위해 Postfix 용 PHP 스크립트를 설정하여 전자 메일이 발송 될 때마다 해당 전자 메일의 사본이 내 스크립트로 전송되도록하고 싶습니다. Postfix에서 필터를 사용하면 문제가 발생하지만 Postfix의 전달 프로세스의 일부로 문제가 발생합니다. 즉, 내 스크립트가 어떤 이유에서든 이메일을 전달하지 못하면 이메일이 전송되지 않습니다. 내가 원하지 않는 것 (너무 많은 책임)입니다. – Mehran

+0

죄송합니다. 다른 질문에 대해 잊어 버렸습니다. 나는 오히려 포스트 픽스에만 집중할 것이다. – Mehran

답변

0

가장 쉬운 방법입니다 (스크립트를 통해 메일을 처리 할 수있는 서버의 메일 함으로 메일을 보낼 수 있습니다).

하지만 스크립트가 이미 이메일을 생성 한 경우 왜 다시 스크립트에 피드해야합니까? Postfix는 message-id 헤더와 다른 지루한 헤더를 추가하지 않습니다 ...

0

들어오는 메일에 내용 필터를 지정할 수 있습니다. 다음과 같이 master.cf 파일을 수정해야합니다 방법 :

... 
smtp inet n - n - - smtpd 
    ... 
    -o content_filter=yourfilter: 
... 
yourfilter unix - n n - - pipe 
    user=[user on which the script will be executed] 
    argv=php /path/to/your/script.php --sender='${sender}' --recipient='${recipient}' 

다음 제대로 제공 된 매개 변수를 사용에서이 메일을 것이라는 방식으로이 script.php를 작성해야합니다 (--sender = ... 그리고 --recipient = ...) mailbody는 stdin에서 제공 될 것입니다. 여기

은 표준 입력에서 이메일을 수있는 방법을 예입니다 (I가 나중에 사용하기 젠드 \ 메일 \ 메시지에서이 하나를 사용 :: fromString()는 메시지 개체를 만들 수) : 파라미터의 지정에 따라

/** 
    * Retrieves raw message from standard input 
    * @throws \RuntimeException if calling controller was not executed on console 
    * @return string raw email message retrieved from standard input 
    */ 
    protected function retrieveMessageFromStdin() { 
     $request = $this->getRequest(); 
     if (!$request instanceof ConsoleRequest) 
      throw new \RuntimeException('Action can be used only as console action !'); 

     $stdin = fopen('php://stdin', 'r'); 
     $mail_contents = ""; 
     while (!feof($stdin)) { 
      $line = fread($stdin, 1024); 
      $mail_contents .= $line; 
     } 
     fclose($stdin); 
     $mail_contents = preg_replace('~\R~u', "\r\n", $mail_contents); 
     return $mail_contents; 
    } 

을 - 저는 ZF2를 사용하여 거기에 콘솔 어플리케이션을 작성하는 방법이나 프레임 워크에보다 적합한 여러 가지 기술을 사용하는 방법을 읽어야합니다.

메일에서 메일을 받기를 원한다면 이메일을 "postject"로 다시 보내야합니다. 내가하는 방법은 다음과 같습니다.

/** 
    * Reinjects message to sendmail queue 
    * 
    * @param array $senders   array of senders to be split into several sender addresses passed to sendmail (in most cases it is only 1 address) 
    * @param array $recipients   array of recipients to be split into several recipient addresses passed to sendmail 
    * @param string $sendmaiLocation sendmailLocation string full path for sendmail (should be taken from config file) 
    * @return number     return value for sendmail 
    */ 
    public function reinject(array $senders, array $recipients, string $sendmaiLocation) { 
     foreach ($senders as $addresses) 
      $senderAddress .= " " . $addresses; 
     foreach ($recipients as $addresses) 
      $recipientAddress .= " " . $addresses; 
     $sendmail = $sendmaiLocation . " -G -i -f '" . $senderAddress . "' -- '" . $recipientAddress . "'"; 
     $handle = popen($sendmail, 'w'); 
     fwrite($handle, $this->toString()); 
     return pclose($handle); 
    } 

기본적으로 위 기능을 사용하여 필요에 따라 사용자 지정할 수 있습니다. 그런 다음 앞서 언급 한 명령 줄 매개 변수의 매개 변수를 사용하여 나중에 실행할 수 있습니다.

희망 사항 :

+0

$가 무엇인지 친절하게 설명해 주시겠습니까? 감사! –

+0

$ this는 Zend \ Mime \ Message 객체를 참조합니다. 위의 코드는 Zne \ Mime \ Message ...를 확장하는 클래스의 일부입니다. 기본적으로 $ this-> toString()의 istead는 후위에 재 주입 될 Mime 메시지가 들어 있습니다. –

관련 문제