3
votes

I'm using CakePHP to send automated emails to clients. It's been working great, but it seems some recipients aren't receiving our emails. So I decided to use the SMTP option for sending emails, and route emails through our email provider at Media Temple. However, when trying to send email from a Media Temple account, I get the error "550- relay not permitted". That sounds like the Media Temple server is just plain not allowing me to send mail through it. That's odd because I've confirmed the username and password I'm using is correct and I can send mail via SMTP through it from my macmail client and iPhone mail client. I've also confirmed my cakephp email settings are correct, because I can send emails via SMTP with a gmail account with the exact same configuration in cakephp. Any idea why I'm getting this error and how to resolve it? Thanks

Here's the code that handles sending an email. I use this class just like the regular EmailComponent from within many different controllers.

    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', '<$1@$2>', trim($subEmail));
    }
    $email=implode(",",$fixedSubEmails);
    return $email;
   }
}
2
That sounded exactly like what I needed, but the suggestions didn't help. The section on "Relaying denied" basically said to verify I'm using password authentication, here are my cakephp settings: $this->smtpOptions = array( 'port'=>'465', 'timeout'=>'30', 'auth' => true, 'host' => 'ssl://mail.thenumber.biz', 'username'=>'[email protected]', 'password'=>{password}, ); it also suggested it wouldn't work if it's a new server, but we've had it for years and are sending emails fine with desktop clients.thespacecamel
Would you mind posting the CakePHP code that's doing the mailing?Hoff
Is your PHP code connecting from the same domain as your Mac/iPhone were when you tested? I believe some relays will also require incoming connections to come from a trusted IP range.eaj
@Hoff Sure I'll post the code, although it's pretty involved.thespacecamel

2 Answers

0
votes

The main problem I was having was that clients weren't receiving emails from our server, (and so I wanted to use an SMTP server to see if that would fix it, instead of the server's default email server). But I managed to get those clients to receive emails from the server by making some other changes, thus removing the need to use SMTP and the Media Temple email server. (As an FYI, I found that we were getting bouncebacks from client email servers stating Diagnostic-Code: smtp; 550 Access denied - Invalid HELO name (See RFC2821 4.1.1.1), but they were being sent directly back to the server, and going into the linux user account "www-data". (I read them in /var/mail/www-data, just using tail and vim). I found that postfix, which was handling the sending of emails, was marking the email sender's hostname (ie, "HELO name") as canadafinds3, the name I gave the server in Rackspace, not the domain name: canadafinds.com. So I changed that in /etc/postfix/main.cf, restarted postfix, et voila! No more bouncebacks from those particular clients, and everyone's happy again.)

0
votes

I ended up writing my own PHP mail() script based on http://www.dreamincode.net/forums/topic/36108-send-emails-using-php-smtp-direct/ in order to circumvent this error.