c# - Deleting Mail from gmail account -
i able send mails attachments multiple users using c# code. want delete sent mail have sent gmail account using c#. there way it.
my code sending mail attachment.
if (mailid1 != null) { system.net.mail.mailmessage mail = new system.net.mail.mailmessage(); try { mailidcount = mailid1.split(',').count(); mailids = new string[mailidcount]; mailids = mailid1.split(','); var adminmail = "user@gmail.com"; var adminpassword = "password123!"; var adminsmtpclient = "smtp.gmail.com" string sub = formobj["subject_text"]+" " + convert.todatetime(datetime.now.touniversaltime()).tostring("dd/mm/yyyy"); mail.subject = sub; mail.from = new system.net.mail.mailaddress(adminmail); mail.to.add(mailids[0]); if (mailidcount > 0) { (int = 1; < mailidcount; a++) { mail.cc.add(mailids[a]); } } mail.body = "<pre>" +formobj["message_text"] +"</pre>"; mail.isbodyhtml = true; string filename; string filename = path.getfilename(infile.filename); filename = path.combine(appdomain.currentdomain.basedirectory + "\\content\\trialfolder\\filefolder\\" + filename); if (infile.contentlength > 0) { infile.saveas(filename); system.net.mail.attachment attached; attached = new system.net.mail.attachment(filename); mail.attachments.add(attached); } if (sub != null) { mail.isbodyhtml = true; system.net.mail.smtpclient smtp = new system.net.mail.smtpclient(adminsmtpclient); smtp.host = adminsmtpclient; smtp.port = "587"; smtp.usedefaultcredentials = true; smtp.enablessl = true; smtp.credentials = new system.net.networkcredential(adminmail, adminpassword); smtp.send(mail); if (system.io.file.exists(filename) == true) { try { mail.attachments.dispose(); system.io.file.delete(filename); mail.dispose(); smtp.dispose(); } catch (exception ex) { viewbag.message = ex.message; } } tempdata["emailmessage"] = "your message has been sent successfully"; } else { tempdata["emailmessage"] = "please check email settings"; } }
there's entire api gmail => https://developers.google.com/gdata/client-cs
Comments
Post a Comment