title: Email sent through localhost but not sent when I try to send from my Server
body: <p>Email sent through localhost but not sent when I try to send from my Server.</p>
  
  <p>What to Do.</p>
  
  <p><strong>note :</strong> I was use <code>port</code> 25 and <code>host</code> : mail.mydomain.com.</p>
  
  <blockquote>
    <p>Failure sending mail.</p>
  </blockquote>
  
  <p>Could you help me please?</p>
  
  <p>I have used this code:</p>
  
  <pre><code>public static string SendMail(string host , string from , string pass , int port , string pTo, string subject, string body, string attach)
      {
          string Host = host;
          string ReceiverEmailAddres = pTo;
          string SenderEmailAddresss = from;
          string SenderEmailPassword = pass;
  
          SmtpClient MyMail = new SmtpClient();
  
          MailMessage MyMsg = new MailMessage();
  
          MyMail.Host = Host;
  
          MyMail.Port = port;
          MyMsg.To.Add(new MailAddress(ReceiverEmailAddres));
          MyMsg.Subject = subject;
  
          if (attach != string.Empty)
          {
              Attachment data = new Attachment(attach);
              MyMsg.Attachments.Add(data);
          }
  
          MyMsg.IsBodyHtml = true;
          MyMsg.From = new MailAddress(SenderEmailAddresss);
  
          MyMsg.Body = body;
  
  
          MyMail.UseDefaultCredentials = false;
          NetworkCredential MyCredentials = new NetworkCredential(SenderEmailAddresss, SenderEmailPassword);
          MyMail.Credentials = MyCredentials;
  
          try
          {
              MyMail.Send(MyMsg);
              return "ok";
          }
          catch(Exception ex)
          {
              return ex.Message;
          }
      }
  </code></pre>