asp.net - Error while sending mail - The SMTP server requires a secure connection or the client was not authenticated -
i have tried every example available on net still no working,whenever click on submit button shows error ,please me this
protected void btnsubmit_click(object sender, imageclickeventargs e) { dal.s_email = txtforget.text; datatable dt = new datatable(); dt = bal.forgot_pass(dal); if (dt.rows.count > 0) { system.net.mail.mailmessage msg = new system.net.mail.mailmessage(); msg.from = new mailaddress("my@email.com"); msg.to.add(txtforget.text); msg.subject = "yor password details"; msg.body = "hi,<br>please check login details<br/><br/> username : " + dt.rows[0]["username"] + "<br/><br/> password " + dt.rows[0]["password"] + "<br/><br/>"; msg.isbodyhtml = true; smtpclient smtp = new smtpclient(); smtp.host = "smtp.gmail.com"; smtp.port = 587; smtp.enablessl = true; smtp.usedefaultcredentials = false; smtp.credentials = new system.net.networkcredential("my@email.com", "****"); smtp.send(msg); label2.text = "your username , password sent"; txtforget.text = ""; } else { label2.text = "email not registered"; } }
web config
<system.net> <mailsettings> <smtp from="my@email.com"> <network host="smtp.gmail.com" password="****" port="587" username="my@email.com" defaultcredentials="false" enablessl="true"/> </smtp> </mailsettings> </system.net>
try
protected void btnsubmit_click(object sender, imageclickeventargs e) { mailmessage mail = new mailmessage(); mail.to.add(toemail); mail.from = new mailaddress("my@email.com"); mail.subject = "mail"; mail.body = " hi,<br>please check login details<br/><br/> username : " + dt.rows[0]["username"] + "<br/><br/> password " + dt.rows[0]["password"] + "<br/><br/>"; smtpclient smtp = new smtpclient(); smtp.host = "smtp.gmail.com"; smtp.port = 587; smtp.usedefaultcredentials = false; smtp.credentials = new system.net.networkcredential("my@email.com", "password"); smtp.enablessl = true; smtp.send(mail); }
Comments
Post a Comment