I have developed asp.net application which sends email to the domain of my company. Example : ex@companydomain.com, but I'm not able to send it to any other domains, like ex@gmail.com or ex1@hotmail.com. Do I need to make changes in the smtp server or in my code? Please let me know. I'm pretty new to .net.Below is the code which I used :
MailMessage Msg = new MailMessage();
var MailResult = false;
var EmailUser = RFSvc.Users.Where(u => u.Email == email).SingleOrDefault();
if (EmailUser != null)
{
Msg.From = new MailAddress("noreply@example.com", "Company name");
Msg.Subject = "Password Recovery";
Msg.IsBodyHtml = true;
Msg.Body = "Your User Name is: " + EmailUser.Username + "<br /> Your password is: " + EmailUser.Password;
Msg.To.Add(email);
SmtpClient MailClient = new SmtpClient();
MailClient.UseDefaultCredentials = false;
MailClient.Host = "mail.example.com";
MailClient.Port = 25;
MailClient.Credentials = new NetworkCredential("username","password");
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
MailClient.EnableSsl = false;
try
{
MailClient.Send(Msg);
MailResult = true;
}
catch (Exception)
{
}
}