title: Mailbox unavailable. The server response was: relay not permitted
body: <p>I am sending emails via an external SMTP server. Sending the email is handled with this code:</p>
  
  <pre><code>try
      {
          System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
          mail.From = new MailAddress(froma);
          mail.To.Add(toc);
          mail.Subject = subject;
          mail.IsBodyHtml = true;
          mail.Body = body;
          SmtpClient smtp = new SmtpClient(ClientServer);
          DataSet ds = new DataSet();
          int retCode = Email.getSmtp(ref ds, DatabaseName);
          string User="";
          string Password="";
  
          if (ds.Tables["Value"].Rows.Count &gt; 0)
          {
              User = ds.Tables["Value"].Rows[0]["UserName"].ToString();
              Password = ds.Tables["Value"].Rows[0]["PasswordName"].ToString();
          }
          else
          {
              MessageBox.Show("Invalid SMTP settings!");
              return;
          }
  
          smtp.UseDefaultCredentials = false;
          smtp.Credentials = new System.Net.NetworkCredential(User, Password);
          smtp.EnableSsl = false;
          smtp.Send(mail);
      }
      catch (System.Web.HttpException exHttp)
      {
          System.Console.WriteLine("Exception occurred:" + exHttp.Message);
      }
  </code></pre>
  
  <p>Testing this code on my server, with my own SMTP server on the same network, this returns all my emails. However, using an external SMTP server causes the error:</p>
  
  <pre><code>Mailbox unavailable. The server response was: relay not permitted.
  </code></pre>
  
  <p>I have read around and it appears that the admin for SMTP must allow relays for my server. However, using the authentication credentials provided, I can't seem to connect, and am still receiving the relay error.</p>