When a data is inserted into two different tables, a confirmation email should be send to the client. below is the code which i am using for sending the email.Please reply asap.
string consstring = ConfigurationManager.ConnectionStrings["connstring"].ConnectionString;
string s2 = "insert into Enquiry_Form values('" + name.Text +
"','" + countrycode+
"','" + mobile.Text+
"','" + email.Text +
"','" + city.Text +
"','" + message.Text + "')";
con =
new SqlConnection(consstring);
con.Open();
SqlCommand cmd;
cmd =
new SqlCommand(s2, con);
cmd.ExecuteNonQuery();
MailMessage msg = new MailMessage();
msg.Subject =
"Enquiry";
msg.From =
new MailAddress("sender email id");
msg.To.Add("receiver email id");
SmtpClient smp = new SmtpClient("smtp.gmail.com");
smp.Port = 587;
smp.Credentials =
new NetworkCredential("sender email id", "password");
smp.Send(msg);

sathish kumarPosted Jun 11, 2012, 8:00 AM
introduction
Many times i have seen on our dotnetspider website users put their question related to email sending using ASP.NET.
This is a small attempt to help all developers who unaware of email sending using ASP.NET
Things Required before building code
we should keep all mandatory tools in our toolbox before building code, here is list of required things
1. Receiver Email address
2. Sender Email: UserID and Password
3. Namespace System.Net.Mail
4. Email Attachment if any
5. Last but not least you should keep enable your mail for POP settings in your Gmail account
following screen shot will clear idea
Getting started
After collecting all required tool let's starts with the website creation
1. create a website in visual studio
----------------------------------------------
2. Design form as per requirement, i have design a simple form here you can check
----------------------------------------------
3. put following code in your code behind, on send email click in TRY...CATCH block
MailMessage mail = new MailMessage();
//put mail from Email
mail.From = new MailAddress("[email protected]");
//put mail to Email
mail.To.Add(new MailAddress("[email protected]"));
//you can add blank carbon copy mails here
//mail.Bcc.Add(new MailAddress("YOUR BCC EMAIL"));
//Get an attachment in attachment variable class
Attachment att = new Attachment("D:\\test.txt");
//add attachment to email
mail.Attachments.Add(att);
//Put email subject
mail.Subject = "Send Email with Gmail using ASP.NET";
//Put email body
string Body = "Put your Email Body TEXT here";
// Here you can put HTML string if you want email to be sent in HTML format.
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "PASSWORD");
//keep ssl true if you have to send email with secured socket layer
smtp.EnableSsl = false;
smtp.Send(mail);
----------------------------------------------
now your code is ready to send email using ASP.NET
Exception points
There are so many factor that may affects your email sending code, here is list,
1. Firewall block port 587 (This is port for smtp gmail server)
2. Internet connection is not available on machine or internet connection has face some obstacles while pinging
3. Due to some typo mistake UserName and password may be get wrong
4. Enable SSL is block email sending
5. POP settings for smtp server in your Gmail account is disabled
Hope this link will help yoy
Ajay PatelPosted Jun 4, 2012, 8:24 AM
http://ajaypatelfromsanthal.blogspot.in/2012/05/send-mail-from-gmail-in-c.html
Satyapriya NayakPosted Jun 1, 2012, 11:16 PM
Please refer Our recommended articles
Thanks
sudharsan sPosted Jun 1, 2012, 7:40 AM
http://www.c-sharpcorner.com/uploadfile/anjudidi/email-sending-in-Asp-Net-2-0/default.aspx
http://www.c-sharpcorner.com/UploadFile/dchoksi/SendingMail02132007002923AM/SendingMail.aspx