【问题标题】:Can't send email via SMTP because "550 - Relay Not permitted"无法通过 SMTP 发送电子邮件,因为“550 - 不允许中继”
【发布时间】:2012-08-12 07:18:05
【问题描述】:

我正在使用 CakePHP 向客户发送自动电子邮件。它一直运行良好,但似乎有些收件人没有收到我们的电子邮件。所以我决定使用 SMTP 选项来发送电子邮件,并通过我们位于 Media Temple 的电子邮件提供商发送电子邮件。 但是,当尝试从 Media Temple 帐户发送电子邮件时,我收到错误“550 - 不允许中继”。 听起来 Media Temple 服务器只是简单地不允许我通过它发送邮件。 这很奇怪,因为我已经确认我使用的用户名和密码是正确的,并且我可以通过我的 macmail 客户端和 iPhone 邮件客户端通过 SMTP 发送邮件。我还确认我的 cakephp 电子邮件设置是正确的,因为我可以使用与 cakephp 中完全相同的配置的 gmail 帐户通过 SMTP 发送电子邮件。 知道为什么我会收到此错误以及如何解决它吗? 谢谢

这是处理发送电子邮件的代码。我在许多不同的控制器中使用这个类,就像使用常规的 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,//'USERNAME@gmail.com',
            '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', '<$1@$2>', trim($subEmail));
    }
    $email=implode(",",$fixedSubEmails);
    return $email;
   }
}

【问题讨论】:

  • 这听起来完全符合我的需要,但这些建议没有帮助。关于“中继被拒绝”的部分基本上说要验证我正在使用密码身份验证,这是我的 cakephp 设置:$this-&gt;smtpOptions = array( 'port'=&gt;'465', 'timeout'=&gt;'30', 'auth' =&gt; true, 'host' =&gt; 'ssl://mail.thenumber.biz', 'username'=&gt;'michael@thenumber.biz', 'password'=&gt;{password}, ); 它还建议如果它是一个新服务器它将无法工作,但我们已经拥有它多年了使用桌面客户​​端发送电子邮件正常。
  • 您介意发布用于发送邮件的 CakePHP 代码吗?
  • 您的 PHP 代码连接的域与您测试时的 Mac/iPhone 是否相同?我相信某些中继还需要来自受信任 IP 范围的传入连接。
  • @Hoff 当然我会发布代码,虽然它很复杂。

标签: php email cakephp smtp mediatemple


【解决方案1】:

我遇到的主要问题是客户端没有从我们的服务器接收电子邮件,(因此我想使用 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)。我发现处理电子邮件发送的后缀将电子邮件发件人的主机名(即“HELO名称”)标记为canadafinds3,我给的名字Rackspace 中的服务器,而不是域名:canadafinds.com。所以我在 /etc/postfix/main.cf 中更改了它,重新启动了 postfix,等等!这些特定客户端不再反弹,每个人都再次感到高兴。)

【讨论】:

    【解决方案2】:

    为了规避这个错误,我最终基于http://www.dreamincode.net/forums/topic/36108-send-emails-using-php-smtp-direct/ 编写了自己的 PHP mail() 脚本。

    【讨论】:

      猜你喜欢
      • 2020-02-21
      • 2015-01-11
      • 2013-11-28
      • 2018-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多