I am trying to send mail from localhost with the following asp.net code..but email sending is becoming failed..
why is it so/???
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage mail = new MailMessage();
string name = TextBox1.Text.ToString();
string contact = TextBox2.Text.ToString();
mail.To.Add("email@gmail.com");
mail.From = new MailAddress(name.Trim());
mail.Subject = "In line image test";
mail.Body = "Hello email...." +name.Trim() +", "+contact.Trim();
mail.IsBodyHtml = true;
SmtpClient client = new SmtpClient("127.0.0.1");
client.UseDefaultCredentials = false;
client.EnableSsl = true;
client.Host = "127.0.0.1";
client.Port = 25;
NetworkCredential credentials = new NetworkCredential("email@gmail.com", "abc");
client.Credentials = credentials;
try
{
client.Send(mail);
}
catch
{
Button1.Text = "Fail";
}
}
Thanks in advance..
try this