easy code for sending main
protected void Button1_Click(object sender, EventArgs e)
{
str = "Department :" + DropDownList1.SelectedItem;
str = str + "\nName : " + TextBox1.Text;
str = str + "\nEmail : " + TextBox2.Text;
str = str + "\nContact : " + TextBox3.Text;
try
{
Email("dksingh6788@gmail.com", "dksingh6788@gmail.com", str);
Label6.Visible = true;
}
catch { }
}
public bool Email(string strFrom, string strTo, string strMessage)
{
try
{
if (strFrom.Trim() != "" && strTo.Trim() != "" && strFrom.Trim() != null && strTo.Trim() != null)
{
System.Net.Mail.MailMessage objMailMessage = new System.Net.Mail.MailMessage();
objMailMessage.Body = strMessage;
objMailMessage.BodyEncoding = System.Text.Encoding.UTF8;
objMailMessage.IsBodyHtml = false;
objMailMessage.From = new MailAddress(strFrom, "New Enquiry", System.Text.Encoding.UTF8);
objMailMessage.To.Add(new MailAddress(strTo));
objMailMessage.Subject = "Registration Request";
objMailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
objMailMessage.Priority = MailPriority.High;
try
{
System.Net.Mail.SmtpClient objSMTPClient = new System.Net.Mail.SmtpClient();
objSMTPClient.Credentials = new System.Net.NetworkCredential(strFrom, "lalakidukan");
objSMTPClient.Port = 587;
objSMTPClient.Host = "smtp.gmail.com";
objSMTPClient.EnableSsl = true;
objSMTPClient.Send(objMailMessage);
}
catch (Exception ex)
{
return false;
}
Label6.Visible = false;
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
}
}
catch (Exception ex)
{
return false;
}
return true;
}