c# - Can't send word documents (.doc and .docx) as email attachment from form -
i'm trying send email attachment form myself. works succesfully when add .pdf file attachment. fails when try .doc or .docx file.
i've added validation in javascript, accepts every file type need:
var validfiletypes = ["doc", "docx", "pdf", "tiff"];
this c# code check form , send email:
private bool sendjobmail() { var client = new mailerservicereference.iemailclient(); var succeeded = false; string _recipient = "jobs@company.eu"; string _firstname = firstname.value; string _lastname = lastname.value; string _telnr = phone.value; string _motivation = motivation.value; string _sender = "info@company.eu"; int vacid = int32.parse(vacancyid.value); string vactitle = _vacancies.find(vac => vac.id == vacid).title; string subject = string.format("application {0} {1} {2}", _firstname, _lastname, vactitle); _motivation += string.format("\n\n{0}{1}\n{2}\n{3}", _firstname, _lastname, email.value, _telnr); //set , add attachment string attachmentfilename = path.getfilename(cv.postedfile.filename); attachment attachment = new attachment(cv.filecontent, attachmentfilename, mediatypenames.application.octet); //can interpret pdf , richtextdocument contentdisposition disposition = attachment.contentdisposition; //disposition necessary mailing applications disposition.creationdate = file.getcreationtime(attachmentfilename); disposition.modificationdate = file.getlastwritetime(attachmentfilename); disposition.readdate = file.getlastaccesstime(attachmentfilename); disposition.filename = path.getfilename(attachmentfilename); disposition.size = cv.postedfile.contentlength; disposition.dispositiontype = dispositiontypenames.attachment; try { client.open(); client.sendemail("companypublicsite", _sender, _recipient, subject, _motivation); succeeded = true; } catch (exception e) { console.writeline(e.message); } { client.close(); } return succeeded; }
if need additional code, let me know.
Comments
Post a Comment