api - EWS Get Attachments and plain text body C# -
i writing desk application , user can log ticket using email have used ews api pick on emails , store subject line , body in plain text database.
i store attachments having trouble bodytype cannot text, must html allow attachments stored require body in plain text when storing database.
i got code storing plain text link ews body plain text. can't seem find of interest attachments.
my code far:
itempropertyset.requestedbodytype = bodytype.text; email.load(); bb = email.body.text; try {// add new ticket db string stmt = "insert tickets(subject, statusid, priorityid, createdbyuserid, createddatetime, clientdescription, tickettypeid) values (@subject, @sid, @pid, @cid, @ctd, @cd, @tid); select scope_identity() id"; cmd = new sqlcommand(stmt, conn); cmd.parameters.addwithvalue("@subject", ss); //subject line email cmd.parameters.addwithvalue("@sid", 1); //default open cmd.parameters.addwithvalue("@pid", 6); //default prioirity normal cmd.parameters.addwithvalue("@cid", userid); //gettheuserid cmd.parameters.addwithvalue("@ctd", datetime.now); cmd.parameters.addwithvalue("@cd", bb); //subject line email cmd.parameters.addwithvalue("@sid", 2); //default email sqldataadapter da = new sqldataadapter(cmd); datatable dte = new datatable("res"); da.fill(dte); if (dte.rows.count > 0) { decimal tid = convert.todecimal(dte.rows[0]["id"]); try { //add new activity ticket string stmnt = "insert activities(ticketid, activitytypeid, createdbyuserid, subject, activitycontent, createddatetime) values (@tid, @atid, @cid, @subject, @ac, @ctd ); select scope_identity() id";; sqlcommand cmde = new sqlcommand(stmnt, conn); cmde.parameters.addwithvalue("@tid", tid); //subject line email cmde.parameters.addwithvalue("@atid", 3); //default email cmde.parameters.addwithvalue("@cid", userid); //gettheuserid cmde.parameters.addwithvalue("@subject", ss); cmde.parameters.addwithvalue("@ac", bb); cmde.parameters.addwithvalue("@ctd", datetime.now); sqldataadapter sdtc = new sqldataadapter(cmde); datatable sdta = new datatable("activitytable"); sdtc.fill(sdta); if (sdta.rows.count > 0 && email.hasattachments == true) { decimal aid = convert.todecimal(sdta.rows[0]["id"]); foreach(microsoft.exchange.webservices.data.attachment attachment in email.attachments) { if (attachment fileattachment) { fileattachment = attachment fileattachment; fileattachment.load("\\\\helpdesk\\attachments\\" + attachment.name); } else { itemattachment itemattachment = attachment itemattachment; itemattachment.load(); } string path = "\\\\helpdesk\\attachments\\" + attachment.name; string stmtattach = "insert attachment(ticketid, activityid, attachmenttypeid, createdbyuserid, createddatetime, attachmentpath) values (@tid, @aid, @atid, @cid, @cdt, @path)"; sqlcommand comd = new sqlcommand(stmtattach, conn); comd.parameters.addwithvalue("@tid", tid); comd.parameters.addwithvalue("@aid", aid); comd.parameters.addwithvalue("@atid", 1); comd.parameters.addwithvalue("@cid", userid); comd.parameters.addwithvalue("@cdt", datetime.now); comd.parameters.addwithvalue("@path", path); sqldataadapter ada = new sqldataadapter(comd); datatable adte = new datatable("attachment"); ada.fill(adte); } } sendmail(sendername, email.sender.address, "ticket?" + tid.tostring() + "#" + ss, "original message: " + bb + "your ticket has been added helpdesk ticket " + tid); } catch (system.exception ex) { console.writeline(ex); lg.appendline(" - unsuccessful adding activity db.<br/>"); } } }
if understand problem correctly, want body text of attachment.
to need use item.textbody property.
so below:
itemattachment itemattachment = attachment itemattachment; itemattachment.load(new propertyset(emailmessageschema.textbody)); console.writeline(itemattachment.item.textbody);
Comments
Post a Comment