c# - Loop for resending smtp email on failure to send -
c# - Loop for resending smtp email on failure to send -
i have service sends email after user registers. every 1 time in while, user contacts back upwards complaint aren't receiving email, i've made list of possible issues, 1 of smtp failure send email, noticed when step through code. want write simple loop tries resend email couple of times on failure send, i'm not sure how go doing that. i'd appreciate advice on subject.
public void musicdownloademail(string email) { seek { var smtp = new smtpclient(); var mail service = new mailmessage(); const string mailbody = "body text"; mail.to.add(email); mail.subject = "mail subject"; mail.body = mailbody; mail.isbodyhtml = true; smtp.send(mail); } grab (exception ex) { var exception = ex.message.tostring(); //other code saving exception message log. } }
something should trick:
public void musicdownloademail(string email) { int tryagain = 10; bool failed = false; { seek { failed = false; var smtp = new smtpclient(); var mail service = new mailmessage(); const string mailbody = "body text"; mail.to.add(email); mail.subject = "mail subject"; mail.body = mailbody; mail.isbodyhtml = true; smtp.send(mail); } grab (exception ex) // avoid catching exceptions equally, ymmv { failed = true; tryagain--; var exception = ex.message.tostring(); //other code saving exception message log. } }while(failed && tryagain !=0) }
c# email smtpclient
Comments
Post a Comment