my intention code send email summary of total reports sent in day , send me summary of every day.these reports stored in database code works fine need add functions it:
- subject includes date , total reports sent every day
within body, want include total unfinished reports sent , total reports sent.
program prog = new program(); bool flag = prog.sendmail(); if (flag) { console.write("success!"); } console.read(); } public bool sendmail() { mailmessage msg = new mailmessage(); msg.to.add("email"); msg.from = new mailaddress("email");//mail account msg.subject = "fls reports sent "; // o subject = reports sent – {date} – {total reports sent} msg.subjectencoding =system.text.encoding.utf8; msg.isbodyhtml =false; // interim reports sent – total unfinished reports sent , total reports sent msg.priority = mailpriority.high; smtpclient client = new smtpclient(); client.credentials = new system.net.networkcredential("","password"); client.host = "smtp.qq.com"; object userstate = msg; try { client.sendasync(msg, userstate); return true; } catch(exception ex) { console.writeline(ex.message); return false; } }
this connection string database
sqlconnection con = new sqlconnection(@"data source= (localdb)\projects;initial catalog=fls_db; integrated security=true;connect timeout=30;encrypt=false;"); try { sqlcommand mycmd = con.createcommand(); mycmd.commandtext = (" select count(*) services servicetype= 1 or servicetype= 2"); con.open(); sqldatareader reader = mycmd.executereader(); { while (reader.read()) { console.writeline("service type = " + reader[0]); } } while (reader.nextresult()); { reader.close(); } console.readkey(); } catch (sqlexception e) { console.writeline(e.message); } { con.close(); }
my question how includes date , total reports sent every day within subject in email? how include total number of unfinished , completed reports within body of email?