title: Can't send email via SMTP because "550 - Relay Not permitted"
body: <p>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</p>
  
  <p>Here's the code that handles sending an email. I use this class just like the regular EmailComponent from within many different controllers.</p>
  
  <pre><code>    class CanadafindsEmailerComponent extends EmailComponent 
  { 
      ...
      function send($content = null, $template = null, $layout = null) {  
      if(!in_array(TECHY_MONITOR_EMAIL,$this-&gt;bcc) &amp;&amp; is_array($this-&gt;bcc))
          $this-&gt;bcc[]=TECHY_MONITOR_EMAIL;
      else if (!in_array(TECHY_MONITOR_EMAIL,$this-&gt;bcc) &amp;&amp; !is_array($this-&gt;bcc))
          $this-&gt;bcc=array(TECHY_MONITOR_EMAIL);
      if(DEVSITE){//commented-out code are settings for smtp with gmail, which works fine
          $this-&gt;delivery = 'smtp'; 
          $this-&gt;smtpOptions = array(
              'port'=&gt;'465',//'465', 
              'timeout'=&gt;'30',//'30',
              'auth' =&gt; true,
              'host' =&gt; 'ssl://mail.thenumber.biz',//'ssl://smtp.gmail.com',
              'username'=&gt;USERNAME,//'USERNAME@gmail.com',
              'password'=&gt;SMTP_PASSWORD//,
          );
          $this-&gt;to=$this-&gt;correctFormatOn($this-&gt;to);
          $this-&gt;bcc=$this-&gt;correctFormatOn($this-&gt;bcc);
          $this-&gt;cc=$this-&gt;correctFormatOn($this-&gt;cc);
          $this-&gt;replyTo=$this-&gt;correctFormatOn($this-&gt;replyTo);
          $this-&gt;from=$this-&gt;correctFormatOn($this-&gt;from);
      }
      return parent::send($content,$template,$layout);
     }
     function correctFormatOn(&amp;$email){
      if(is_array($email)){
          $copiedEmail=array();
          foreach($email as $singleEmail){
              $copiedEmail[]=$this-&gt;correctFormatOnSingle($singleEmail);
          }
          $email=$copiedEmail;
      }else{
          $email=$this-&gt;correctFormatOnSingle($email);
      }
      return $email;
  
     }
  
     function correctFormatOnSingle(&amp;$email){
      $subEmails=explode(",",$email);
      $fixedSubEmails=array();
      foreach($subEmails as $subEmail){
          $fixedSubEmails[]=preg_replace('/&lt;?([^&lt; ]+)@([^&gt;,]+)[&gt;,]?/i', '&lt;$1@$2&gt;', trim($subEmail));
      }
      $email=implode(",",$fixedSubEmails);
      return $email;
     }
  }
  </code></pre>