使用后缀检索“回复”电子邮件地址并通过管道传输到文件

使用后缀检索“回复”电子邮件地址并通过管道传输到文件

我一直在从事一个项目,用于接收发送到域的任何电子邮件地址(无论该电子邮件是否存在),然后我们必须将该电子邮件传送到 .php 脚本进行进一步处理。

我已经设置了 Postfix 来接收发送到域的任何电子邮件,并且它工作正常。配置如下

我的问题是我需要能够向我们的客户提供一个我们域中不存在的电子邮件地址。示例是“[电子邮件保护]。然后我们将收到一封发送到该地址的电子邮件,该地址在我们的服务器上不存在,但我们希望提取公司名称和公司帐户 ID 并将其与我们的客户匹配,然后将电子邮件发送到他们帐户上的正确电子邮件。

问题是电子邮件地址“[电子邮件保护]当脚本从 Postfix PIPE 进程接收电子邮件时,在 .php 脚本中找不到“。我原本以为 Postfix 会发送一个“回复”来保存这个电子邮件地址,但如果您看到下面的代码和电子邮件转储,就会发现它不在那里,我不知道接下来该怎么做。

以下是我如何配置 Postfix 的工作方式:创建一个虚拟用户表:

@globalvrm.com globalvrm_email

postmap /usr/local/etc/postfix/virtusertable

创造:

virtusertable.db

将域添加到本地主机名文件:

/usr/local/etc/postfix/local-host-names
globalvrm.com #domain

在“/usr/local/etc/postfix/main.cf”中添加了以下几行:

home_mailbox = Maildir/
    mailbox_command =
    virtual_maps = hash:/usr/local/etc/postfix/virtusertable
    mydestination = /usr/local/etc/postfix/local-host-names

我正在从 STDIN 阅读电子邮件,如下所示:

function mailRead($iKlimit = "")
    {

            // Set default limit of 1024k if no limit has been specified
            if ($iKlimit == "") {
                $iKlimit = 1024;
            }

            // Error strings
            $sErrorSTDINFail = "Error - failed to read mail from STDIN!";

        // Attempt to connect to STDIN
        $fp = fopen("php://stdin", "r");

        // Failed to connect to STDIN? (shouldn't really happen)
        if (!$fp) {
            echo $sErrorSTDINFail;
            exit();
        }

        // Create empty string for storing message
        $sEmail = "";

        // Read message up until limit (if any)
        if ($iKlimit == -1) {
            while (!feof($fp)) {
                $sEmail .= fread($fp, 1024);
            }                    
        } else {
            while (!feof($fp) && $i_limit < $iKlimit) {
                $sEmail .= fread($fp, 1024);
                $i_limit++;
            }        
        }

        // Close connection to STDIN
        fclose($fp);

        // Return message
        return $sEmail;
    }

    //Read email
    $email = mailRead($iKlimit = "-1");
$xx = print_r($email,true); 

我尝试转储 $email 中的结果,如下所示:

    From [email protected] Sat Mar 30 21:15:57 2019 Received: from alora.out.smtp.thehostdomain.com (alora.out.smtp.thehostdomain.com [209.33.201.216]) by server1.adifferentdomain.com (Postfix) with ESMTP id 50309E60CE for ; Sat, 30 Mar 2019 21:15:57 -0600 (MDT) 
Received: from tdcmail1.thehostdomain.com (tdcmail1.thehostdomain.com [IPv6:2604:2c00:0:103::40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.thehostdomain.com", Issuer "GeoTrust TLS RSA CA G1" (not verified)) by alora.out.smtp.thehostdomain.com (Postfix) with ESMTPS id 44X0ws0cNMzMyHw for ; Sat, 30 Mar 2019 21:15:57 -0600 (MDT) 
Received: from Sales1 (209-33-199-176-dsl.thehostdomain.net [203.33.333.333]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: [email protected]) by tdcmail1.thehostdomain.com (Postfix) with ESMTPSA id 44X0wr3QMPzMxP1 for ; Sat, 30 Mar 2019 21:15:56 -0600 (MDT) 
From: "Aaron LastNAme" To: Subject: asdf Date: Sat, 30 Mar 2019 21:15:55 -0600 Message-ID: MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_NextPart_000_0536_01D4E73D.C6D95460" X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AdTncA15uyXIYYirTp2PzuqlPDq6SA== Content-Language: en-us This is a multi-part message in MIME format. ------=_NextPart_000_0536_01D4E73D.C6D95460 Content-Type: multipart/alternative; boundary="----=_NextPart_001_0537_01D4E73D.C6D95460" ------=_NextPart_001_0537_01D4E73D.C6D95460 Content-Type: text/plain; charset="us-ascii" 
Content-Transfer-Encoding: 7bit ffffffff thedomain | Aaron LastNAme toll free: 1.800.222.2222, ext. 501 email: [email protected] website: www.thedomain.com https://thedomain.com/graphics/logo.png facebook_email_icon Follow us on Facebook twitter_email_icon Follow us on Twitter CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is for the sole use of the intended recipients and may contain confidential or proprietary information. Any unauthorized review, use, disclosure or distribution is prohibited. ------=_
NextPart_001_0537_01D4E73D.C6D95460 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 

我没能在任何地方找到那个“回复”电子邮件地址。

我如何获得它?提前致谢!

答案1

回复:标头不是强制性的。

如果回复:缺少你必须使用从:,如果没有找到,你可以查找第一行

答案2

我通过将内容写入 .txt 文件解决了这个问题。当我查看该文件时,发现其中的“收件人:”是电子邮件地址,然后我在 php 中 cat 该文件并 grep 出电子邮件地址。希望这能帮助遇到同样问题的人。

相关内容