Sunday, 15 June 2014

c# - my contact us asp.net page doesn't send email -


I am designing a website by asp.net c #, and i am starting to language i contact us The page has been created and I have followed the tutorials Alto but it is not working, anyone can help me, what is the error? This is my contactus.aspx page: & lt;

  Table & gt; & Lt ;! - Name - & gt; & Lt; TR & gt; & Lt; Td align = "center" & gt; Name: & lt; / TD & gt; & Lt; Td style = "width: 327 px" & gt; & Lt; ASP: Text Box ID = "Test Name" Run = "Server" Column = "50" & gt; & Lt; / Asp: text box & gt; & Lt; / TD & gt; & Lt; Td style = "width: 306 px" & gt; & Amp; Nbsp; & Lt; / TD & gt; & Lt; / TR & gt; & Lt ;! - subject - & gt; & Lt; TR & gt; & Lt; Td align = "center" & gt; Email: & lt; / Td> & Lt; Td style = "width: 327 px" & gt; & Lt; Asp: text box id = "txtEmail" runat = "server" column = "50" texts = "email" & gt; & Lt; / Asp: text box & gt; & Lt; / TD & gt; & Lt; Td style = "width: 306 px" & gt; & Lt; Asp: RegularExpressionValidator ID = "RegularExpressionValidator1" runat = "server" controlToValidate = "txtEmail" error message = "Please enter email address" validationExpress = "\ w + ([- +. '] \ W +) * @ \ w + ([-.] \ W +) * \ \ w + ([-] \ w +) * "& gt; & Lt; / ASP: .. RegularExpressionValidator & gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt ;! - message - & gt; & Lt; TR & gt; & Lt; Td align = "center" & gt; Subject & lt; / TD & gt; & Lt; Td style = "width: 327 px" & gt; & Lt; ASP: Text Box ID = "Textsbeak" Runat = "Server" column = "50" & gt; & Lt; / Asp: text box & gt; & Lt; / TD & gt; & Lt; Td style = "width: 306 px" & gt; & Amp; Nbsp; & Lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td align = "center" & gt; Message: & lt; / Td> & Lt; Td style = "width: 327 px" & gt; & Lt; ASP: text box id = "text message" runat = "server" column = "40" lines = "6" textual = "multiline" & gt; & Lt; / Asp: text box & gt; & Lt; / TD & gt; & Lt; Td style = "width: 306 px" & gt; & Amp; Nbsp; & Lt; / TD & gt; & Lt; / TR & gt; & Lt ;! - Submit - & gt; & Lt; Tr align = "center" & gt; & Lt; Td colspan = "2" & gt; & Lt; ASP: Button ID = "BTN submit" runat = "server" text = "submit" onclick = "btnSubmit_Click" style = "width: 61px" /> & Lt; / TD & gt; & Lt; Td style = "width: 306 px" & gt; & Amp; Nbsp; & Lt; / TD & gt; & Lt; / TR & gt; & Lt ;! - Results - & gt; & Lt; Tr align = "center" & gt; & Lt; Td colspan = "2" & gt; & Lt; Asp: Label ID = "lblResult" runat = "server" & gt; & Lt; / Asp: label & gt; & Lt; / TD & gt; & Lt; Td style = "width: 306 px" & gt; & Amp; Nbsp; & Lt; / TD & gt; & Lt; / TR & gt; & Lt; / Table & gt;  

And this is my code behind contactus.aspx.cs:

  secure void btnSubmit_Click (object sender, EventArgs e) {try {MailMessage mailMessage = New} MailMessage (); MailMessage.From = New Mail Address ("ranna.fal@gmail.com"); MailMessage.To.Add ("ranna.fal@gmail.com"); MailMessage.Subject = txtsubject.Text; MailMessage.Body = "& lt; b & gt; Sender's Name: & lt; / b & gt;" + TxtName.Text + "& lt; br / & gt;" + "& Lt; b & gt; From Email: & lt; / b & gt;" + TxtEmail.Text + "
" + "& Lt; b & gt; Comments: & lt; / b & gt;" + TxtMessage.Text; MailMessage.IsBodyHtml = True; SmtpClient smtpClient = new SmtpClient ("smtp.gmail.com", 587); SmtpClient.EnableSsl = true; SmtpClient.Credentials = New System.Net.NetworkCredential ("ranna.fal@gmail.com", "My password"); SmtpClient.Send (MailMessage); LblResult.ForeColor = System.Drawing.Color.Blue; LblResult.Text = "Thank you for contacting us"; TxtName.Enabled = false; TxtEmail.Enabled = false; TxtMessage.Enabled = false; Txtsubject.Enabled = false; BtnSubmit.Enabled = false; } Hold (Exception Pre) {// Exception Notification // Database Table or Event Viewer lblResult.ForeColor = System.Drawing.Color.Red; LblResult.Text = "There is an unknown problem, please try later"; }}

I also included this: using System.Net.Mail; Text: An unknown problem. Please try later,

thanks

If you have 2 factors authentication To turn on, you'll need a device-specific password or 2-factor authentication will be turned off.


No comments:

Post a Comment