c# - Seding email via WPF make app shutdown -
when try send email on computer enviroment(visual studio 2015) fine when copied computer(vmware virtual machine) , try run shutdown, here main code:
try { smtpclient client = new smtpclient(); client.port = 587; client.host = "smtp.gmail.com"; client.enablessl = true; client.timeout = 10000; client.deliverymethod = smtpdeliverymethod.network; client.usedefaultcredentials = false; client.credentials = new system.net.networkcredential("bazymysql@gmail.com", "xyz"); mailmessage mm = new mailmessage("donotreply@domain.com", "bazymysql@gmail.com", "przechwycony ciag znakow", tresc.text); mm.bodyencoding = utf8encoding.utf8; mm.deliverynotificationoptions = deliverynotificationoptions.onfailure; client.send(mm); } catch (smtpexception ex) { messagebox.show(ex.message); } what i've tried:
- copy system.net dll
- developing 86x 64x
- run admin
maybe can try following
try { smtpclient client = new smtpclient(); client.port = 587; client.host = "smtp.gmail.com"; client.enablessl = true; client.timeout = 10000; client.deliverymethod = smtpdeliverymethod.network; client.usedefaultcredentials = false; client.credentials = new system.net.networkcredential("bazymysql@gmail.com", "xyz"); mailmessage mm = new mailmessage("donotreply@domain.com", "bazymysql@gmail.com", "przechwycony ciag znakow", tresc.text); mm.bodyencoding = utf8encoding.utf8; mm.deliverynotificationoptions = deliverynotificationoptions.onfailure; thread sendmailthread = new thread(()=>{ client.send(mm); //this ensure sending happens on second thread , not crash main thread. }); sendmailthread.start(); } catch (smtpexception ex) { messagebox.show(ex.message); }
Comments
Post a Comment