We are trying to send mails using our own company SMTP clinet say mail.companyname.com and by using port number.
In my company we have restriction like we can't send Mail out of office using our Company Email Id's. But for this From: Address we have access to send to out of office too like xxx@gmail.com still not able to send it showing some excetion like "Mailbox unavailable. The server response was: 5.7.1 Unable to relay."..
But by using same email id we can able to send mail to with in office Email Id...
MailMessage message = new MailMessage();
message.To.Add(new MailAddress("Email ID"));
message.From = new MailAddress("Email ID");
message.Subject = "Test mail";
message.Body = "thBody";
message.BodyEncoding = System.Text.Encoding.UTF8;
message.SubjectEncoding = System.Text.Encoding.UTF8;
SmtpClient client = new SmtpClient();
client.Port = 25;
client.Host = "mail.companyname.com";
System.Net.NetworkCredential nc = new System.Net.NetworkCredential("Email ID", "password@00");
//client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = nc;
client.Send(message);