mail to does not work to send a mail if u r sending mail uisng Asp .net
then
// use this code to send mail but it only work with gmail if you r working with other then change this code nly port no
objSMTPClient.Port = 587;
using System.Net.Mail;
using System.Text;
protected void Submit_Click(object sender, EventArgs e)
{
if (Txt1.Text == "")
{
Label6.Visible = true;
Label6.Text = "Enter The company name";
}
else if (TextBox2.Text == "")
{
Label6.Visible = true;
Label6.Text = "Enter The Full name";
}
else if (TextBox3.Text == "")
{
Label6.Visible = true;
Label6.Text = "Enter The EMail";
}
else if (TextBox4.Text == "")
{
Label6.Visible = true;
Label6.Text = "Enter The Contact no";
}
else if (TextBox5.Text == "")
{
Label6.Visible = true;
Label6.Text = "Enter The dESCRIPTION";
}
else
{
String str;
str = "Full Name :" + Txt1.Text.ToUpper();
str = str + "Company : " + TextBox2.Text;
str = str + "Email : " + TextBox3.Text;
str = str + "Contact no : " + TextBox4.Text;
str = str + "Description : " + TextBox5.Text;
try
{
Email("dksingh6788@gmail.com", "devendrak@fitatechnologies.com", str);
Response.Redirect("Thanku.aspx");
}
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, "One Ghost", System.Text.Encoding.UTF8);
objMailMessage.To.Add(new MailAddress(strTo));
//objMailMessage.CC.Add(new MailAddress(strTo));
objMailMessage.Subject = "Registration Request";
objMailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
objMailMessage.Priority = MailPriority.High;
//if (FileUpload1.HasFile)
//{
// objMailMessage.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
//}
try
{
System.Net.Mail.SmtpClient objSMTPClient = new System.Net.Mail.SmtpClient();
objSMTPClient.Credentials = new System.Net.NetworkCredential(strFrom, "you gmail password");// please insert gmail password
//objSMTPClient.Credentials = objSMTPClient.Credentials.GetCredential(objSMTPClient.Host, objSMTPClient.Port, "Digest");
objSMTPClient.Port = 587;
objSMTPClient.Host = "smtp.gmail.com";
objSMTPClient.EnableSsl = true;
//objSMTPClient.DeliveryMethod = SmtpDeliveryMethod.Network;
objSMTPClient.Send(objMailMessage);
}
catch (Exception ex)
{
return false;
}
}
}
catch (Exception ex)
{
return false;
}
return true;
}