0

我构建了一个小脚本来运行在 Joomla 网站内发送电子邮件的端到端测试:

$testMailer =& JFactory::getMailer();

$testMailer->setSender(SENDER);
$testMailer->addReplyTo(SENDER);
$testMailer->addRecipient(TEST_EMAIL);

$subject = 'Automatic test '.md5(uniqid());

$testMailer->setSubject($subject);
$testMailer->setBody('This message is automatically retrieved. Please ignore.');

?>
<h2>Testing Joomla email sending functionality</h2><?php
flush();
if ($testMailer->Send() !== true) {
    echo '<p>ERROR - Mail Sending failed</p>';
}else{

    echo '<p>Email sent...</p>';
    flush();
    $sleep = 5;
    $progress = 0;
    $max = 300;
    set_time_limit($max+30);
    $found = 0;

    $mbox = imap_open(TEST_IMAP_SERVER, TEST_EMAIL, TEST_PASSWORD);

    if (!$mbox){
        echo '<p>ERROR - Login to '.TEST_EMAIL.' failed</p>';
        foreach (imap_errors() as $error){
            echo '<p>'.$error.'</p>';
        }
        die();
    }else{
        while (!$found && $progress < $max){

            $result = imap_search($mbox, 'SUBJECT "'.$subject.'"');

            foreach($result as $msgno) {
                $headers = imap_fetchheader($mbox, $msgno);
                if ($headers){
                    echo '<p>OK - EMail received</p>';
                    imap_delete($mbox,$msgno);
                    $found = 1;
                    die();
                }
            }
        }
        if (!$found){
            $progress+=$sleep;
            echo '<p>Waiting '.$sleep.' seconds to try again...('.$progress.' seconds total wait)</p>';
            flush();
            sleep($sleep);
        }
    }
    if (!$found){
        echo '<p>ERROR Giving up after '.$max.' seconds</p>';
    }
}

该脚本在我的本地开发机器上运行良好,并且始终可以找到发送的消息。

实时站点位于 Amazon EC2 服务器上。起初,我收到了异常登录活动的警告。我确认脚本是已知的,并在 10 分钟内重新运行。

此后,脚本可以登录,但 imap_search 再也找不到任何消息。但是,它们确实会到达收件箱。开发站点上的脚本仍然可以正常工作。

亚马逊服务器上的 Telnet 也可以正常工作

telnet imap.gmail.com 993
Trying 74.125.133.108...
Connected to gmail-imap.l.google.com.
Escape character is '^]'.

有任何想法吗?

4

0 回答 0