c# - Attaching auto generated pdf to email in asp.net app -
i have specific requirement. in web app, have generate pdf invoice database values, , email body. can send using smtp works perfect.
but, problem can't rely on system perfect, , invoice. so, need open default mail client instead of using smtp. right now, have following code
//code create script email string emailjs = ""; emailjs += "window.open('mailto:testmail@gmail.com?body=test mail" + "&attachment=" + emailattachment + "');"; //register script post clientscript.registerstartupscript(this.gettype(), "mailto", emailjs, true);
this opens email perfectly, no attachment working. path supposed /web/temp/123.pdf
.
if use same path normal url below, opens file in new window properly.
clientscript.registerstartupscript(this.gettype(), "newwindow", "window.open('/web/temp/123.pdf');", true);
so, file exists, exists on server. outlook on other hand open on client machine. so, can't use full determined path c:\web\temp\123.pdf
. if try that, try find file on client machine, folder might not exist.
i trying figure out can here. if there method should try.
p.s. no, can't send email directly. cause hell lot more problem in future me.
edit: found 1 weird problem. if add double quote file path in attachment, \ added automatically. @"&attachment=""" + server.mappath(emailattachment) + @"""');"
gives me output &attachment=\"c:\web\temp\123.pdf\"
.
i trying escape double quote , somehow adds slash. know different problem, thought should mention here, instead of creating new question.
edit: tried fixed path on localhost. so, testing app on same machine file getting stored. still, no attachment @ all.
string emailjs = ""; emailjs += @"window.open('mailto:jitendragarg@gmail.com?body=test mail" + emailattachment + @"&attachment="; emailjs += @"""d:\dev\csms\csmsweb\temp\635966781817446275.pdf""');"; //emailjs += server.mappath(emailattachment) + @"');"; //register script post clientscript.registerstartupscript(this.gettype(), "mailto", emailjs, true);
updated path make sure proper. now, throws error saying command line argument not valid
.
edit:
is there other method can try? have file path on server side. maybe can download file automatically default folder on client machine , open there? possible?
edit: tried 1 more option.
emailjs += @"mailto:testmail@gmail.com?body=test mail" + @"&attachment="; emailjs += @"\\localhost\csmsweb\temp\635966781817446275.pdf"; //emailjs += server.mappath(emailattachment) + @"');"; process.start(emailjs);
the process.start
line works nothing @ all. there no process starts, no error either.
edit: yay. got user approve using separate form display subject , body, instead of opening default mail client. although, still prefer solve problem is.
so, problem here fact mailto
supports direct file path attachment. is, path has local use machine, or intranet path within network.
in other words, path http://yourapp/web/temp/123.pdf
won't work, , /web/temp/123.pdf
being same won't work either. these not paths, links files has downloaded , stored locally before can used attachments - mailto protocol has no support that.
however, since application intranet, make sure intended users have access network shared folder on server, , provide them network path file, \\theserver\files\123.pdf
Comments
Post a Comment