<System.Net> <mailsettings> <SMTPDeliverymethod= "Network" from= "Lai hai Fei Xia Garments Co., Ltd. < [Email protected]>]> <NetworkHost= "Smtp.163.com"UserName= "[email protected]"Password="****" /> </SMTP> </mailsettings> </System.Net>
Above is the configuration file.
protected voidButton1_Click (Objectsender, EventArgs e) { if(page.isvalid) {stringFileName = Server.MapPath ("~/app_data/contactform.txt"); stringMailbody =File.readalltext (fileName); Mailbody= Mailbody.replace ("# #name # #", TextBox1.Text); Mailbody= Mailbody.replace ("# #email # #", TextBox2.Text); Mailbody= Mailbody.replace ("# #phone # #", TextBox3.Text); Mailbody= Mailbody.replace ("# #comments # #", Textbox4.text); Try { //Send yourself a letterMailMessage mail =NewMailMessage (); Mail. from=NewMailAddress ("[email protected]","Lihai Garments Co., Ltd."); Mail. To.add (NewMailAddress ("[email protected]","SQ")); Mail. Subject="from Lihai Clothing official website"; Mail. Body=Mailbody; Mail. Bodyencoding=System.Text.Encoding.Default; //send a letter to the customerMail. To.add (Newmailaddress (TextBox2.Text)); SmtpClient Client=NewSmtpClient (); Client. Send (mail); Response.Write ("<script>alert (' send Success ');</script>"); } Catch(Exception ex) {Response.Write ("<script>alert ('"+ ex. Message +"');</script>"); } } }
Then the button is implemented.
Darling # #name # #您好! I'm glad to see the message on our official website! Name: # #name # #邮箱: # #email # #电话: # #phone # #留言: # #comments # #我们收到邮件会及时看的哦 ~ need to reply to the first time to reply to you ~ If you are particularly anxious, and did not receive my reply, Can directly call my mobile 132****7727 (Chen Manager) Thank the Pro patronage, I wish you a happy life! The money is wide in! I'm going to do it!
Finally, a txt text file.
That's OK! haha ^_^
Self-study "1. Email the website