2012-08-15 186 views
2

我正在使用CakePHP向客戶端發送自動電子郵件。它工作得很好,但似乎有些收件人沒有收到我們的電子郵件。因此,我決定使用SMTP選項發送電子郵件,並通過Media Temple的電子郵件提供商路由電子郵件。 但是,當試圖從Media Temple帳戶發送電子郵件時,出現錯誤「550-不允許繼電器」。 這聽起來像Media Temple服務器只是簡單地不允許我通過它發送郵件。 這很奇怪,因爲我確認了我使用的用戶名和密碼是正確的,我可以通過SMTP通過它從我的macmail客戶端和iPhone郵件客戶端發送郵件。我還確認我的cakephp電子郵件設置是正確的,因爲我可以通過SMTP發送電子郵件,並使用與cakephp完全相同的配置的gmail帳戶。 任何想法,爲什麼我得到這個錯誤,以及如何解決它? 謝謝無法通過SMTP發送電子郵件,因爲「550 - 中繼不允許」

下面是處理髮送電子郵件的代碼。我像使用許多不同控制器中的普通EmailComponent一樣使用這個類。

class CanadafindsEmailerComponent extends EmailComponent 
{ 
    ... 
    function send($content = null, $template = null, $layout = null) { 
    if(!in_array(TECHY_MONITOR_EMAIL,$this->bcc) && is_array($this->bcc)) 
     $this->bcc[]=TECHY_MONITOR_EMAIL; 
    else if (!in_array(TECHY_MONITOR_EMAIL,$this->bcc) && !is_array($this->bcc)) 
     $this->bcc=array(TECHY_MONITOR_EMAIL); 
    if(DEVSITE){//commented-out code are settings for smtp with gmail, which works fine 
     $this->delivery = 'smtp'; 
     $this->smtpOptions = array(
      'port'=>'465',//'465', 
      'timeout'=>'30',//'30', 
      'auth' => true, 
      'host' => 'ssl://mail.thenumber.biz',//'ssl://smtp.gmail.com', 
      'username'=>USERNAME,//'[email protected]', 
      'password'=>SMTP_PASSWORD//, 
     ); 
     $this->to=$this->correctFormatOn($this->to); 
     $this->bcc=$this->correctFormatOn($this->bcc); 
     $this->cc=$this->correctFormatOn($this->cc); 
     $this->replyTo=$this->correctFormatOn($this->replyTo); 
     $this->from=$this->correctFormatOn($this->from); 
    } 
    return parent::send($content,$template,$layout); 
    } 
    function correctFormatOn(&$email){ 
    if(is_array($email)){ 
     $copiedEmail=array(); 
     foreach($email as $singleEmail){ 
      $copiedEmail[]=$this->correctFormatOnSingle($singleEmail); 
     } 
     $email=$copiedEmail; 
    }else{ 
     $email=$this->correctFormatOnSingle($email); 
    } 
    return $email; 

    } 

    function correctFormatOnSingle(&$email){ 
    $subEmails=explode(",",$email); 
    $fixedSubEmails=array(); 
    foreach($subEmails as $subEmail){ 
     $fixedSubEmails[]=preg_replace('/<?([^< ]+)@([^>,]+)[>,]?/i', '<[email protected]$2>', trim($subEmail)); 
    } 
    $email=implode(",",$fixedSubEmails); 
    return $email; 
    } 
} 
+3

看看這裏:[解決媒體寺SMTP問題](http://kb.mediatemple.net/questions/74/Troubleshooting+SMTP+problems#gs) – paulsm4 2012-08-15 23:30:36

+0

這聽起來完全像我所需要的,但建議didn'幫助。上的「被拒絕的傳遞」基本上說來驗證我使用的密碼驗證,這裏是我的CakePHP設置: '$這個 - > smtpOptions =陣列( \t「口」 =>「465」, \t「超時」 > '30', \t 'AUTH'=>真, \t '主機'=> 'SSL://mail.thenumber.biz', \t '用戶名'=> '[email protected]', \t'password'=> {密碼}, \t); ' 它也表明它不會工作,如果它是一個新的服務器,但我們已經有多年,併發送電子郵件與桌面客戶端罰款。 – thespacecamel 2012-08-15 23:59:20

+0

你介意發佈做郵件的CakePHP代碼嗎? – Hoff 2012-08-16 14:15:23

回答

0

我遇到的主要問題是客戶不從我們的服務器接收電子郵件,(所以我想用一個SMTP服務器來看看是否能夠解決它,而不是服務器的默認電子郵件服務器)。 但我設法讓這些客戶端通過進行其他更改來接收來自服務器的電子郵件,從而消除了使用SMTP和Media Temple電子郵件服務器的需要。 (作爲供參考,我發現我們得到客戶電子郵件服務器的反彈,說明Diagnostic-Code: smtp; 550 Access denied - Invalid HELO name (See RFC2821 4.1.1.1),但他們直接發送回服務器,並進入Linux用戶帳戶「www-data」(我在/ var/mail/www-data,只是使用tail和vim),我發現postfix處理電子郵件的發送,它將電子郵件發件人的主機名(即「HELO name」)標記爲canadafinds3,服務器在Rackspace中,而不是域名:canadafinds.com。所以我改變了/etc/postfix/main.cf,重新啓動了postfix,等等!沒有更多的反彈從這些特定的客戶端,並且每個人都很開心。)