pdf sent as MailAttachment arrives corrupt
Author |
Message |
vincent mout #1 / 15
|
 pdf sent as MailAttachment arrives corrupt
hi, i'm using, coded in C#, the SmtpMail object to send HTML-mails with attachments. Users can access a web interface where they define the HTML file that will make up the body of the e-mail, and define the attachment to be sent with that mail. In this case the attachment will always be a .pdf file. After having submitted the form, the code-behind saves both of these files on the server, and re-opens them to add them as body of the e-mail and attachment. i add the attachments working like this: //FileName is a string variable hodling the full path on the server and filename of the file MailAttachment TheAttach = new MailAttachment(Server.MapPath(FileName)); //MyMsg is an instance of the class MailMessage MyMsg.Attachments.Add(TheAttach); When the e-mail arrives at the user's mail client, the pdf file attached seems corrupt and gives several errors (Too few operands, invalid token,...) I opened the files that the code-behind first saved on the server and they open up well. I tried several pdf files to be sure the file itself is not corrupt, but the errors remained. Has anyone had any previous similar problems (not only with pdf attachments). Could this be caused by the fact that i first save the pdf file on the server and then attach it to the mail message (which may lead to attaching a non-complete file) thanks, v
|
Fri, 04 Mar 2005 21:25:21 GMT |
|
 |
Microsoft MV #2 / 15
|
 pdf sent as MailAttachment arrives corrupt
I am in the middle of trying to resolve this issue as I am seeing it pop up all over the place and it my pet project just now. Ironically, it only seems to happen with PDF files. You will get better results in the mail if you uuencode the attatchment, but it may still fail intermittently as I have discovered. As an immediate fix dont send the attachment as a file, send a link to the file on your server, use either a hyperlink or a HTML email with a meta refresh to an aspx that will stream the file to the end user. Regards John Timney (Microsoft ASP.NET MVP) ---------------------------------------------- <shameless_author_plug> Professional Windows Forms ISBN: 1861005547 Professional JSP ISBN: 1861003625 Beginning JSP Web Development ISBN: 1861002092 </shameless_author_plug> ----------------------------------------------
Quote: > hi, > i'm using, coded in c#, the SmtpMail object to send HTML-mails with > attachments. > Users can access a web interface where they define the HTML file that > will make up the body of the e-mail, and define the attachment to be > sent with that mail. In this case the attachment will always be a .pdf > file. > After having submitted the form, the code-behind saves both of these > files on the server, and re-opens them to add them as body of the > e-mail and attachment. > i add the attachments working like this: > //FileName is a string variable hodling the full path on the server > and filename of the file > MailAttachment TheAttach = new > MailAttachment(Server.MapPath(FileName)); > //MyMsg is an instance of the class MailMessage > MyMsg.Attachments.Add(TheAttach); > When the e-mail arrives at the user's mail client, the pdf file > attached seems corrupt and gives several errors (Too few operands, > invalid token,...) > I opened the files that the code-behind first saved on the server and > they open up well. I tried several pdf files to be sure the file > itself is not corrupt, but the errors remained. > Has anyone had any previous similar problems (not only with pdf > attachments). > Could this be caused by the fact that i first save the pdf file on the > server and then attach it to the mail message (which may lead to > attaching a non-complete file) > thanks, > v
|
Sat, 05 Mar 2005 03:18:14 GMT |
|
 |
Zane Thomas [.NET MV #3 / 15
|
 pdf sent as MailAttachment arrives corrupt
On Mon, 16 Sep 2002 20:18:14 +0100, "John Timney \(Microsoft MVP\)" Quote:
>You will get better results in the mail if you uuencode the attatchment, but >it may still fail intermittently as I have discovered.
What do you mean? Doesn't the MailMessage class take care of encoding attachments? Quote: >As an immediate fix >dont send the attachment as a file
Another fix would be to get a third party product that works. -- *--------={ Fine Art for .NET }=--------*
*---------------------------------------* Turn on, tune in, download.
|
Sat, 05 Mar 2005 04:24:06 GMT |
|
 |
Jacky Kwo #4 / 15
|
 pdf sent as MailAttachment arrives corrupt
Quote:
> hi, > i'm using, coded in c#, the SmtpMail object to send HTML-mails with > attachments. > Users can access a web interface where they define the HTML file that > will make up the body of the e-mail, and define the attachment to be > sent with that mail. In this case the attachment will always be a .pdf > file. > After having submitted the form, the code-behind saves both of these > files on the server, and re-opens them to add them as body of the > e-mail and attachment. > i add the attachments working like this: > //FileName is a string variable hodling the full path on the server > and filename of the file > MailAttachment TheAttach = new > MailAttachment(Server.MapPath(FileName)); > //MyMsg is an instance of the class MailMessage > MyMsg.Attachments.Add(TheAttach); > When the e-mail arrives at the user's mail client, the pdf file > attached seems corrupt and gives several errors (Too few operands, > invalid token,...) > I opened the files that the code-behind first saved on the server and > they open up well. I tried several pdf files to be sure the file > itself is not corrupt, but the errors remained. > Has anyone had any previous similar problems (not only with pdf > attachments). > Could this be caused by the fact that i first save the pdf file on the > server and then attach it to the mail message (which may lead to > attaching a non-complete file) > thanks, > v
Hi: You can try to use another constructor of MailAttachment. public MailAttachment(string filename,MailEncoding encoding); try different MailEncoding may help you. -- Jacky Kwok
|
Sat, 05 Mar 2005 09:48:19 GMT |
|
 |
vincent mout #5 / 15
|
 pdf sent as MailAttachment arrives corrupt
Hi all, thanks for the replies. i've tried adding different encoding to my mail attachments, but, as i thought, that didn't make any difference. The PDF attachment never arrived as it should. But i found out that the file actually arrives incomplete. When chechking the precise file size of the original PDF before being attached and the one arriving attached to the mail measage, there was a slight difference in size (each time exactly 207 bytes). I have encountered similar "problems" saving JPG files. After saving them on the server (through c# code-behind), when loaded into a browser, there was still a small part of the file black (a black band at the bottom). As it seems, the process saving the files is pretty quick, but takes seconds (minutes?) to end the last step of the process. Which, i guess, is happening here. The pdf file is saved, and right away added as attachment to the mail message. Thus i'm attaching an incomplete file. This is what i found up till now. I don't know for sure if this is the exact reason. So would there be a way to add a delay in the code-behind telling: save the pdf, now wait a minute or 5, send the e-mail. thanks, v
|
Sat, 05 Mar 2005 17:09:08 GMT |
|
 |
vincent mout #6 / 15
|
 pdf sent as MailAttachment arrives corrupt
Hi, another update. My previous post is still applicable, but, when i watch my webfolder under wwwroot, the file is immediatly saved in it's full size. Or it goes so quickly that the code still sends an incomplete file but when i look at the folder in Explorer 'in real time', i can only see the complete file being dropped in the webfolder. Or i'm just talking nonsens. cheers, v
|
Sat, 05 Mar 2005 19:49:33 GMT |
|
 |
Per Hultqvis #7 / 15
|
 pdf sent as MailAttachment arrives corrupt
Hi, I just looked through a sample of this exact situation, from DataDynamics and the samples that follows with ActiveReports.Net. If you download the trial version of AR.Net (at www.datadynamics.com) and check out the samples you will find one that generates a PDF and then attaches it to a mail and sends it. I tried it this morning and it worked fine, so you might want to compare your code to theirs... /Per Hultqvist
Quote: > hi, > i'm using, coded in c#, the SmtpMail object to send HTML-mails with > attachments. > Users can access a web interface where they define the HTML file that > will make up the body of the e-mail, and define the attachment to be > sent with that mail. In this case the attachment will always be a .pdf > file. > After having submitted the form, the code-behind saves both of these > files on the server, and re-opens them to add them as body of the > e-mail and attachment. > i add the attachments working like this: > //FileName is a string variable hodling the full path on the server > and filename of the file > MailAttachment TheAttach = new > MailAttachment(Server.MapPath(FileName)); > //MyMsg is an instance of the class MailMessage > MyMsg.Attachments.Add(TheAttach); > When the e-mail arrives at the user's mail client, the pdf file > attached seems corrupt and gives several errors (Too few operands, > invalid token,...) > I opened the files that the code-behind first saved on the server and > they open up well. I tried several pdf files to be sure the file > itself is not corrupt, but the errors remained. > Has anyone had any previous similar problems (not only with pdf > attachments). > Could this be caused by the fact that i first save the pdf file on the > server and then attach it to the mail message (which may lead to > attaching a non-complete file) > thanks, > v
|
Sat, 05 Mar 2005 20:12:51 GMT |
|
 |
Microsoft MV #8 / 15
|
 pdf sent as MailAttachment arrives corrupt
Quote: > What do you mean? Doesn't the MailMessage class take care of encoding > attachments?
I thought so - now I'm adding the encoding type, and it still fails - but intermittently. In fact, a whole bunch of PDF files now arrive fine, that failed when I did not specify uuencode. -- Regards John Timney (Microsoft ASP.NET MVP) ---------------------------------------------- <shameless_author_plug> Professional Windows Forms ISBN: 1861005547 Professional JSP ISBN: 1861003625 Beginning JSP Web Development ISBN: 1861002092 </shameless_author_plug> ----------------------------------------------
Quote: > On Mon, 16 Sep 2002 20:18:14 +0100, "John Timney \(Microsoft MVP\)"
> >You will get better results in the mail if you uuencode the attatchment, but > >it may still fail intermittently as I have discovered. > What do you mean? Doesn't the MailMessage class take care of encoding > attachments? > >As an immediate fix > >dont send the attachment as a file > Another fix would be to get a third party product that works. > -- > *--------={ Fine Art for .NET }=--------*
> *---------------------------------------* > Turn on, tune in, download.
|
Sun, 06 Mar 2005 05:07:23 GMT |
|
 |
Microsoft MV #9 / 15
|
 pdf sent as MailAttachment arrives corrupt
So what happens if you use the mail code with a PDF file that is just there - not created using your app. Thus discounting the potential timing problems that may be there in creating the file and then sending? -- Regards John Timney (Microsoft ASP.NET MVP) ---------------------------------------------- <shameless_author_plug> Professional Windows Forms ISBN: 1861005547 Professional JSP ISBN: 1861003625 Beginning JSP Web Development ISBN: 1861002092 </shameless_author_plug> ----------------------------------------------
Quote: > Hi, > another update. > My previous post is still applicable, but, when i watch my webfolder > under wwwroot, the file is immediatly saved in it's full size. > Or it goes so quickly that the code still sends an incomplete file but > when i look at the folder in Explorer 'in real time', i can only see > the complete file being dropped in the webfolder. > Or i'm just talking nonsens. > cheers, > v
|
Sun, 06 Mar 2005 05:09:09 GMT |
|
 |
Zane Thomas [.NET MV #10 / 15
|
 pdf sent as MailAttachment arrives corrupt
On Tue, 17 Sep 2002 22:07:23 +0100, "John Timney \(Microsoft MVP\)" Quote:
>In fact, a whole bunch of PDF files now arrive fine, that >failed when I did not specify uuencode.
Very strange. -- *--------={ Fine Art for .NET }=--------*
*---------------------------------------* Turn on, tune in, download.
|
Sun, 06 Mar 2005 05:21:12 GMT |
|
 |
vincent mout #11 / 15
|
 pdf sent as MailAttachment arrives corrupt
Hi John, i tried that out too willing to check if my statement was correct. When is just placed a pdf file on the server and loaded it as attachment to the mailmessage, the problem still occured. The file arrived 'incomplete' (the same ammount of bytes were missing). cheers, v
Quote: > So what happens if you use the mail code with a PDF file that is just > there - not created using your app. Thus discounting the potential timing > problems that may be there in creating the file and then sending? > -- > Regards > John Timney (Microsoft ASP.NET MVP) > ---------------------------------------------- > <shameless_author_plug> > Professional Windows Forms > ISBN: 1861005547 > Professional JSP > ISBN: 1861003625 > Beginning JSP Web Development > ISBN: 1861002092 > </shameless_author_plug> > ----------------------------------------------
> > Hi, > > another update. > > My previous post is still applicable, but, when i watch my webfolder > > under wwwroot, the file is immediatly saved in it's full size. > > Or it goes so quickly that the code still sends an incomplete file but > > when i look at the folder in Explorer 'in real time', i can only see > > the complete file being dropped in the webfolder. > > Or i'm just talking nonsens. > > cheers, > > v
|
Sun, 06 Mar 2005 15:38:32 GMT |
|
 |
Microsoft MV #12 / 15
|
 pdf sent as MailAttachment arrives corrupt
Yes, same results as I got. Which to me sems to sugegst there is a rpoblem with the SMTP encoding. -- Regards John Timney (Microsoft ASP.NET MVP) ---------------------------------------------- <shameless_author_plug> Professional Windows Forms ISBN: 1861005547 Professional JSP ISBN: 1861003625 Beginning JSP Web Development ISBN: 1861002092 </shameless_author_plug> ----------------------------------------------
Quote: > Hi John, > i tried that out too willing to check if my statement was correct. > When is just placed a pdf file on the server and loaded it as > attachment to the mailmessage, the problem still occured. > The file arrived 'incomplete' (the same ammount of bytes were > missing). > cheers, > v
Quote: > > So what happens if you use the mail code with a PDF file that is just > > there - not created using your app. Thus discounting the potential timing > > problems that may be there in creating the file and then sending? > > -- > > Regards > > John Timney (Microsoft ASP.NET MVP) > > ---------------------------------------------- > > <shameless_author_plug> > > Professional Windows Forms > > ISBN: 1861005547 > > Professional JSP > > ISBN: 1861003625 > > Beginning JSP Web Development > > ISBN: 1861002092 > > </shameless_author_plug> > > ----------------------------------------------
> > > Hi, > > > another update. > > > My previous post is still applicable, but, when i watch my webfolder > > > under wwwroot, the file is immediatly saved in it's full size. > > > Or it goes so quickly that the code still sends an incomplete file but > > > when i look at the folder in Explorer 'in real time', i can only see > > > the complete file being dropped in the webfolder. > > > Or i'm just talking nonsens. > > > cheers, > > > v
|
Mon, 07 Mar 2005 05:49:32 GMT |
|
 |
Zane Thomas [.NET MV #13 / 15
|
 pdf sent as MailAttachment arrives corrupt
On Wed, 18 Sep 2002 22:49:32 +0100, "John Timney \(Microsoft MVP\)" Quote:
>Which to me sems to sugegst there is a rpoblem >with the SMTP encoding.
Mail.Net works. :-) -- *--------={ Fine Art for .NET }=--------*
*---------------------------------------* Turn on, tune in, download.
|
Mon, 07 Mar 2005 06:31:42 GMT |
|
 |
vincent mout #14 / 15
|
 pdf sent as MailAttachment arrives corrupt
Hi John, my first guess (the incomplete files) was obvioulsy wrong. I looked around some more and found this on Adobe's support pages, which explicitly states that such an error can occur. "PDF file token information or any other textual information can be damaged when the file is transferred to a Web or network server, or sent via e-mail. The damage can be caused by the way the file was transferred (such as FTP or e-mail), or by the application used to transfer it, particularly if you use an older version of the application. The transfer method or the application can also incorrectly add information, such as extra carriage returns." I think we will have to work with a link to a pdf file located on a webserver for now. But i hope this problem will once be solved (it actually should). cheers and thanks for the help, vincent
Quote: > Yes, same results as I got. Which to me sems to sugegst there is a rpoblem > with the SMTP encoding. > -- > Regards > John Timney (Microsoft ASP.NET MVP) > ---------------------------------------------- > <shameless_author_plug> > Professional Windows Forms > ISBN: 1861005547 > Professional JSP > ISBN: 1861003625 > Beginning JSP Web Development > ISBN: 1861002092 > </shameless_author_plug> > ----------------------------------------------
> > Hi John, > > i tried that out too willing to check if my statement was correct. > > When is just placed a pdf file on the server and loaded it as > > attachment to the mailmessage, the problem still occured. > > The file arrived 'incomplete' (the same ammount of bytes were > > missing). > > cheers, > > v
> > > So what happens if you use the mail code with a PDF file that is just > > > there - not created using your app. Thus discounting the potential > timing > > > problems that may be there in creating the file and then sending? > > > -- > > > Regards > > > John Timney (Microsoft ASP.NET MVP) > > > ---------------------------------------------- > > > <shameless_author_plug> > > > Professional Windows Forms > > > ISBN: 1861005547 > > > Professional JSP > > > ISBN: 1861003625 > > > Beginning JSP Web Development > > > ISBN: 1861002092 > > > </shameless_author_plug> > > > ----------------------------------------------
> > > > Hi, > > > > another update. > > > > My previous post is still applicable, but, when i watch my webfolder > > > > under wwwroot, the file is immediatly saved in it's full size. > > > > Or it goes so quickly that the code still sends an incomplete file but > > > > when i look at the folder in Explorer 'in real time', i can only see > > > > the complete file being dropped in the webfolder. > > > > Or i'm just talking nonsens. > > > > cheers, > > > > v
|
Mon, 07 Mar 2005 15:15:06 GMT |
|
 |
Zane Thomas [.NET MV #15 / 15
|
 pdf sent as MailAttachment arrives corrupt
Quote: >"PDF file token information or any other textual information can be >damaged when the file is transferred to a Web or network server, or >sent via e-mail. The damage can be caused by the way the file was >transferred (such as FTP or e-mail), or by the application used to >transfer it, particularly if you use an older version of the >application. The transfer method or the application can also >incorrectly add information, such as extra carriage returns."
That's ridiculous, all it says is that a broken application can mung the file when it's transfered. Duh. :-) And correct mail application or component is perfectly capable of converting the PDF file into a format that can be emailed around the net without being corrupted. -- *--------={ Fine Art for .NET }=--------*
*---------------------------------------* Turn on, tune in, download.
|
Mon, 07 Mar 2005 15:51:15 GMT |
|
|
|