Click here to Skip to main content
15,885,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends

Using asp.net application i am trying to send email but receive the error message.please rectify it

Failure sending mail.

my code is as follows:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;

namespace Letter
{
public partial class WebForm1 : System.Web.UI.Page
{


protected void btnSendmail_Click(object sender, EventArgs e)
{
// System.Web.Mail.SmtpMail.SmtpServer is obsolete in 2.0
// System.Net.Mail.SmtpClient is the alternate class for this in 2.0
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();

try
{
MailAddress fromAddress = new MailAddress(txtEmail.Text, txtName.Text);
smtpClient.Host = "localhost";
smtpClient.Port = 25;
message.From = fromAddress;
message.To.Add("theadminking@gmail.com");
message.Subject = "Feedback";
message.IsBodyHtml = false;
message.Body = txtMessage.Text;
smtpClient.Send(message);
lblStatus.Text = "Message have been sent successfully";
}

catch (Exception ex)
{
lblStatus.Text = "Send Email Failed.
" + ex.Message;
}


}
}
}
Posted
Comments
[no name] 6-Jul-13 8:55am    
Find out what the real error is. Did you have an email server setup on your localhost?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900