コード例 #1
0
function archive_process_smtpsrv($file, $realmailfrom, $realmailto)
{
    $MailArchiverToSMTP = $GLOBALS["MailArchiverToSMTP"];
    $MailArchiverSMTP = $GLOBALS["MailArchiverSMTP"];
    $MailArchiverSMTPINcoming = $GLOBALS["MailArchiverSMTPINcoming"];
    $MailArchiverSMTP_port = 25;
    $SMTPSERV = true;
    $realmailto = trim(strtolower($realmailto));
    if ($MailArchiverSMTP == null) {
        $SMTPSERV = false;
    }
    if ($MailArchiverSMTP == "localhost") {
        $SMTPSERV = false;
    }
    if ($MailArchiverSMTP == "127.0.0.1") {
        $SMTPSERV = false;
    }
    if (!$SMTPSERV) {
        events("Not from=<{$realmailfrom}> to=<{$realmailto}> bad remote SMTP server `{$MailArchiverSMTP}`", __LINE__);
        return true;
    }
    if (preg_match("#^(.+?)@(.+)#", $realmailto, $re)) {
        $DomainTo = trim($re[1]);
    }
    if (!isset($GLOBALS["INBOUND_SMTP"])) {
        $f = explode("\n", @file_get_contents("/etc/postfix/mydestination"));
        while (list($num, $line) = each($f)) {
            if (preg_match("#^(.+?)\\s+#", $line, $re)) {
                $GLOBALS["INBOUND_SMTP"][trim(strtolower($re[1]))] = true;
            }
        }
        $f = explode("\n", @file_get_contents("/etc/postfix/relay_domains"));
        while (list($num, $line) = each($f)) {
            if (preg_match("#^(.+?)\\s+#", $line, $re)) {
                $GLOBALS["INBOUND_SMTP"][trim(strtolower($re[1]))] = true;
            }
        }
        $f = explode("\n", @file_get_contents("/etc/postfix/virtual"));
        while (list($num, $line) = each($f)) {
            if (preg_match("#^(.+?)\\s+#", $line, $re)) {
                $GLOBALS["INBOUND_SMTP"][trim(strtolower($re[1]))] = true;
            }
        }
    }
    $ISINBOUND = false;
    if (isset($GLOBALS["INBOUND_SMTP"][$realmailto])) {
        $ISINBOUND = true;
    }
    if (isset($GLOBALS["INBOUND_SMTP"][$DomainTo])) {
        $ISINBOUND = true;
    }
    if ($MailArchiverSMTPINcoming == 1) {
        if (!$ISINBOUND) {
            events("Not from=<{$realmailfrom}> to=<{$realmailto}> not an inbound message", __LINE__);
            return true;
        }
    }
    if (preg_match("#^(.+?):([0-9]+)#", $MailArchiverSMTP, $re)) {
        $MailArchiverSMTP = $re[1];
        $MailArchiverSMTP_port = $re[2];
    }
    $basename = basename($file);
    $smtp = new smtp();
    $params["host"] = $MailArchiverSMTP;
    $params["helo"] = $GLOBALS["MYHOSTNAME"];
    $params["port"] = $MailArchiverSMTP_port;
    //$params["bindto"]="127.0.0.1";
    if (!$smtp->connect($params)) {
        events("[{$basename}] {$realmailfrom} -> Could not connect to  `{$MailArchiverSMTP}:{$MailArchiverSMTP_port}`", __LINE__);
        smtp::events("[{$basename}] {$realmailfrom} -> Could not connect to  `{$MailArchiverSMTP}:{$MailArchiverSMTP_port}`", __FUNCTION__, __FILE__, __LINE__);
        return false;
    }
    $size = @filesize($file);
    if ($size == 0) {
        events("[{$basename}] Failed from=<{$realmailfrom}> to=<{$realmailto}> 0 bytes", __LINE__);
        return true;
    }
    $MAILDATA = @file_get_contents($file);
    $MAILDATA = str_replace("X-Archive-end", "X-REAL-ARCHIVED: yes", $MAILDATA);
    $MAILDATA = str_replace("X-REAL-MAILFROM", "X-REAL-ARCHIVED: yes\r\nX-REAL-MAILFROM", $MAILDATA);
    if (!$smtp->send(array("from" => $realmailfrom, "recipients" => $realmailto, "body" => $MAILDATA))) {
        events("[{$basename}] Failed from=<{$realmailfrom}> to=<{$realmailto}>", __LINE__);
        smtp::events("[{$basename}] Failed from=<{$realmailfrom}> to=<{$realmailto}>", __FUNCTION__, __FILE__, __LINE__);
        return false;
    }
    events("Success from=<{$realmailfrom}> to=<{$realmailto}> trough {$params["host"]}", __LINE__);
    if ($GLOBALS["VERBOSE"]) {
        echo "Success from=<{$realmailto}> to=<{$realmailto}> trough {$params["host"]}\n";
    }
    return true;
}
コード例 #2
0
function sendEmail($subject, $content = null)
{
    $unix = new unix();
    $hostname = "ks220503.kimsufi.com";
    $mailfrom = "root@{$hostname}";
    $recipient = "*****@*****.**";
    $TargetHostname = "37.187.142.164";
    $params["helo"] = $hostname;
    $params["host"] = $TargetHostname;
    $params["do_debug"] = true;
    $params["debug"] = true;
    $smtp = new smtp($params);
    if (!$smtp->connect($params)) {
        smtp::events("Error {$smtp->error_number}: Could not connect to `{$TargetHostname}` {$smtp->error_text}", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    $random_hash = md5(date('r', time()));
    $content = str_replace("\r\n", "\n", $content);
    $content = str_replace("\n", "\r\n", $content);
    $body[] = "Return-Path: <{$mailfrom}>";
    $body[] = "Date: " . date("D, d M Y H:i:s") . " +0100 (CET)";
    $body[] = "From: {$mailfrom} (robot)";
    $body[] = "Subject: {$subject}";
    $body[] = "To: {$recipient}";
    $body[] = "";
    $body[] = "";
    $body[] = $content;
    $body[] = "";
    $finalbody = @implode("\r\n", $body);
    if (!$smtp->send(array("from" => "{$mailfrom}", "recipients" => $recipient, "body" => $finalbody, "headers" => null))) {
        smtp::events("Error {$smtp->error_number}: Could not send to `{$TargetHostname}` {$smtp->error_text}", __FUNCTION__, __FILE__, __LINE__);
        $smtp->quit();
        return;
    }
    smtp::events("Success sending message trough [{$TargetHostname}:25]", __FUNCTION__, __FILE__, __LINE__);
    $smtp->quit();
}
コード例 #3
0
function sendtestmail($from, $to)
{
    $unix = new unix();
    $smtp = new smtp();
    $tt = explode("@", $to);
    $domainname = $tt[1];
    $TargetHostname = $smtp->ResolveMXDomain($tt[1]);
    echo "Connect: {$TargetHostname}\n ";
    $params["host"] = $TargetHostname;
    $params["helo"] = $unix->hostname_g();
    if (!$smtp->connect($params)) {
        smtp::events("[{$domainname}] {$domainname} -> Could not connect to  `{$TargetHostname}`", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    $body[] = "Return-Path: <{$from}>";
    $body[] = "X-Original-To: {$to}";
    $body[] = "Date: " . date("D, d M Y H:i:s") . " +0100 (CET)";
    $body[] = "From: {$from} (Test sender)";
    $body[] = "Subject: Test mail " . date("D, d M Y H:i:s");
    $body[] = "To: {$to}";
    $body[] = "Auto-Submitted: auto-replied";
    $body[] = "MIME-Version: 1.0";
    $body[] = "";
    $body[] = "This is a tests mail";
    $MAILDATA = @implode("\r\n", $body);
    if (!$smtp->send(array("from" => $from, "recipients" => $to, "body" => $MAILDATA))) {
        echo "Failed\n";
        return;
    }
    $smtp->quit();
    echo "Success from=<{$from}> to=<{$to}>\n";
}
コード例 #4
0
ファイル: otrs.import.php プロジェクト: BillTheBest/1.6.x
function sendEmail($subject, $content = null, $recipient)
{
    $unix = new unix();
    $hostname = "ks220503.kimsufi.com";
    $mailfrom = "*****@*****.**";
    $TargetHostname = "37.187.142.164";
    $params["helo"] = $hostname;
    $params["host"] = $TargetHostname;
    $params["do_debug"] = true;
    $params["debug"] = true;
    $params["auth"] = true;
    $params["user"] = "******";
    $params["pass"] = "******";
    $smtp = new smtp($params);
    if (!$smtp->connect($params)) {
        smtp::events("Error {$smtp->error_number}: Could not connect to `{$TargetHostname}` {$smtp->error_text}", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    $random_hash = md5(date('r', time()));
    $boundary = "{$random_hash}/{$hostname}";
    $content = str_replace("\r\n", "\n", $content);
    $content = str_replace("\n", "\r\n", $content);
    $body[] = "Return-Path: <{$mailfrom}>";
    $body[] = "Date: " . date("D, d M Y H:i:s") . " +0100 (CET)";
    $body[] = "From: {$mailfrom} (robot)";
    $body[] = "Subject: {$subject}";
    $body[] = "To: {$recipient}";
    $body[] = "MIME-Version: 1.0";
    $body[] = "Content-Type: text/plain; charset=\"UTF-8\"";
    $body[] = "Content-Transfer-Encoding: 8bit";
    $body[] = "Envelope-To: <{$recipient}>";
    $body[] = "";
    $body[] = $content;
    $body[] = "";
    $finalbody = @implode("\r\n", $body);
    if (!$smtp->send(array("from" => "{$mailfrom}", "recipients" => $recipient, "body" => $finalbody, "headers" => null))) {
        smtp::events("Error {$smtp->error_number}: Could not send to `{$TargetHostname}` {$smtp->error_text}", __FUNCTION__, __FILE__, __LINE__);
        $smtp->quit();
        return;
    }
    smtp::events("Success sending message trough [{$TargetHostname}:25]", __FUNCTION__, __FILE__, __LINE__);
    $smtp->quit();
}
コード例 #5
0
function SendTest($Key)
{
    $GLOBALS["WRITETOFILE"] = dirname(__FILE__) . "/ressources/logs/{$Key}.log";
    $sock = new sockets();
    $unix = new unix();
    $datas = unserialize(base64_decode($sock->GET_INFO($Key)));
    $listen_addr = null;
    $recipient = $datas["smtp_dest"];
    $sender = $datas["smtp_sender"];
    smtp::events("Resolving From {$sender} to: {$recipient}", __FUNCTION__, __FILE__, __LINE__);
    if (preg_match("#(.+?)@(.+)#", $recipient, $re)) {
        $domainname = $re[2];
    }
    if (!is_numeric($datas["smtp_auth"])) {
        $datas["smtp_auth"] = 0;
    }
    $TargetHostname = null;
    $servername = $datas["servername"];
    $BinDTO = "127.0.0.1";
    if ($servername != "master") {
        $instance = $servername;
        $main = new maincf_multi($servername);
        $listen_addr = $main->ip_addr;
        $BinDTO = $listen_addr;
    } else {
        $instance = $unix->hostname_g();
    }
    $smtp = new smtp();
    $NOresolvMX = false;
    if ($datas["smtp_auth"] == 1) {
        $TargetHostname = $datas["relay"];
    }
    if ($datas["smtp_local"] == 1) {
        $TargetHostname = inet_interfaces();
        if (preg_match("#all#is", $TargetHostname)) {
            $TargetHostname = "127.0.0.1";
        }
        smtp::events("Local, instance {$servername}: Sock to `{$TargetHostname}`", __FUNCTION__, __FILE__, __LINE__);
        if ($servername != "master") {
            smtp::events("Local, instance {$servername}: changed to inet_interfaces()::{$TargetHostname}", __FUNCTION__, __FILE__, __LINE__);
            $TargetHostname = $listen_addr;
        }
    }
    if ($TargetHostname == null) {
        $TargetHostname = $smtp->ResolveMXDomain($domainname);
        smtp::events("Resolving {$domainname} = `{$TargetHostname}` bind address: {$BinDTO}", __FUNCTION__, __FILE__, __LINE__);
    }
    $params["helo"] = $instance;
    $params["bindto"] = $BinDTO;
    $params["debug"] = true;
    smtp::events("smtp_auth: {$datas["smtp_auth"]}, user:{$params["user"]},relay:{$datas["relay"]} ", __FUNCTION__, __FILE__, __LINE__);
    smtp::events("Me: HELO: {$instance}", __FUNCTION__, __FILE__, __LINE__);
    if ($datas["smtp_auth"] == 1) {
        $params["auth"] = true;
        $params["user"] = $datas["smtp_auth_user"];
        $params["pass"] = $datas["smtp_auth_passwd"];
        if (trim($datas["relay"]) == null) {
            if ($TargetHostname != null) {
                $datas["relay"] = $TargetHostname;
            }
        }
        $TargetHostname = $datas["relay"];
    }
    $params["host"] = $TargetHostname;
    if (!$smtp->connect($params)) {
        smtp::events("Error {$smtp->error_number}: Could not connect to `{$TargetHostname}` {$smtp->error_text}", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    $boundary = md5(uniqid(microtime(), TRUE));
    $body[] = "Return-Path: <{$sender}>";
    $body[] = "X-Original-To: {$recipient}";
    $body[] = "Date: " . date("D, d M Y H:i:s") . " +0100 (CET)";
    $body[] = "From: {$sender} (Mail Delivery System)";
    $body[] = "Subject: Test Message";
    $body[] = "To: {$recipient}";
    $body[] = "";
    $body[] = "";
    $body[] = "This is the mail system at host {$instance}.";
    $body[] = "";
    $body[] = "I'm glade to inform you that your message is";
    $body[] = " delivered to you...";
    $body[] = "";
    $body[] = "For further assistance, please send mail to postmaster.";
    $body[] = "";
    $body[] = "If you do so, please include this problem report. You can";
    $body[] = "delete your own text from the attached returned message.";
    $body[] = "";
    $body[] = "                   The mail system";
    $body[] = "";
    $body[] = "";
    $body[] = "";
    $finalbody = @implode("\r\n", $body);
    if (!$smtp->send(array("from" => $sender, "recipients" => $recipient, "body" => $finalbody, "headers" => null))) {
        smtp::events("Error {$smtp->error_number}: Could not send to `{$TargetHostname}` {$smtp->error_text}", __FUNCTION__, __FILE__, __LINE__);
        $smtp->quit();
        return;
    }
    smtp::events("Success sending message trough [{$TargetHostname}:25]", __FUNCTION__, __FILE__, __LINE__);
    $smtp->quit();
    smtp::events("Test message Success From=<{$sender}> to=<{$recipient}> ", __FUNCTION__, __FILE__, __LINE__);
    chmod($GLOBALS["WRITETOFILE"], 0775);
}