I have mvc web app sending an email when new user gets created with following code:
private static void SendMail(User user)
{
string ActivationLink = "http://localhost/Account/Activate/" +
user.UserName + "/" + user.NewEmailKey;
var message = new MailMessage("ashu@gmail.com", user.Email)
{
Subject = "Activate your account",
Body = ActivationLink
};
var client = new SmtpClient("localhost");
client.UseDefaultCredentials = false;
client.Send(message);
}
What’s wrong with my code please tell me.
ERROR : Failure sending mail. {“Unable to connect to the remote server”}
Smtp configuration :

Here are the likely causes of this error:
1 You are not supplying the correct authentication details
2 The port is blocked, for example by a firewall
In your example, I notice you are not specifying the port when you create your
SmtpClient– it may help to specify it.