ASP.NET - How to send mails from Office Domain.

Asked By Ajay Paritala on 04-Mar-13 04:23 PM


We are trying to send mails using our own company SMTP clinet say 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 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...

Can some one please correct the code?

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 = ""; 
        System.Net.NetworkCredential nc = new System.Net.NetworkCredential("Email ID", "password@00"); 
        //client.EnableSsl = true; 
        client.UseDefaultCredentials = false; 
        client.Credentials = nc;