asp.net - Sending a message with C# works locally but silently fails live -
hi, using following code send booking form working locally when put live fails , not sure why:
protected void page_load(object sender, eventargs e) {
} protected void sendmail() { var sdate = startdate.text; var edate = enddate.text; // gmail address send mail var fromaddress = "xxx@googlemail.com"; // address email sending var toaddress = "silverhillcattery@hotmail.co.uk"; //password of gmail address const string frompassword = "xxx"; // passing values , make email formate display string subject = yoursubject.text.tostring(); string body = "from: " + yourname.text + "\n"; body += "email: " + youremail.text + "\n"; body += "contact number: " + txtcontactnumber.text + "\n"; body += "subject: " + yoursubject.text + "\n"; body += "question: \n" + comments.text + "\n"; body += "pet name(s): \n" + txtpetname.text + "\n"; body += "start date: \n" + sdate + "\n"; body += "end date: \n" + edate + "\n"; // smtp settings var smtp = new system.net.mail.smtpclient(); { smtp.host = "smtp.gmail.com"; smtp.port = 587; smtp.enablessl = true; smtp.deliverymethod = system.net.mail.smtpdeliverymethod.network; smtp.credentials = new networkcredential(fromaddress, frompassword); smtp.timeout = 20000; } // passing values smtp object smtp.send(fromaddress, toaddress, subject, body); } protected void button1_click(object sender, eventargs e) { try { //here on button click done sendmail(); displaymessage.text = "thank contacting shortly. if talk us, please call 0208 236 9572"; displaymessage.visible = true; yoursubject.text = ""; youremail.text = ""; yourname.text = ""; comments.text = ""; } catch (exception) { } }
it doesn't send message or display "thank contacting..."
this site www.silverhillcattery.co.uk
any appreciated!
update:
i have added error message suggested , following error:
"the smtp server requires secure connection or client not authenticated"
i issue.
i can guess credentials work in local environment don't in live environment. if code fails exception on send bypass display code , go directly "catch" code.
to debug it, put send after display see happens or more appropriately modify catch (exception) grab error , display that.
catch (exception ex) { displaymessage.text = "failed send email. error = " + ex.message; displaymessage.visible = true; }
Comments
Post a Comment