//My mail function is always showing the exception message of: sending mail failure......//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Net.Mail;
using System.Net;
namespace housing1
{
public partial class Ucomplain : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HousingConnectionString"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("Select Name from Standard_Complain", conn);
DataTable dt = new DataTable();
da.Fill(dt);
DropDownListTOC.DataSource = dt;
DropDownListTOC.DataTextField = "Name";
DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
MailMessage Msg = new MailMessage();
Msg.From = new MailAddress(TextBoxPME.Text);
Msg.To.Add("sunita@indweb.com");
Msg.Body = TextBoxD.Text;
Msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.Credentials = new NetworkCredential(TextBoxPME.Text , "nid100");
client.EnableSsl = true;
client.Send(Msg);
Response.Write("mail send");
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HousingConnectionString"].ConnectionString);
conn.Open();
String str = "select Email from Primary_Member where Flat='" + TextBoxF.Text.Trim() + "'";
SqlCommand comm = new SqlCommand(str, conn);
SqlDataReader reader = comm.ExecuteReader();
if (reader.Read())
{
TextBoxPME.Text = reader["Email"].ToString();
reader.Close();
}
}
}
}