By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,939 Members | 1,638 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,939 IT Pros & Developers. It's quick & easy.

SmtpMail Problems

P: n/a
I generate pdf files on my server and allow users to access them via a
browser and also email them. Most files work fine whether the user uses his
browser or gets an email with a pdf attachment which he can then open with
Acrobat. All my pdf files work fine via a browser, but some are corrupted
by one byte when sent as an email attachment. The problem is 100%
reproducible - the code is trivial. Am I missing something obvious or is
this a bug with SmtpMail. ie

Imports System.Web.Mail

Dim ms As New MailMessage
ms.To = "so*******@someplace.com"
ms.From = "so*****@somewhere.com"
ms.BodyFormat = MailFormat.Text
ms.Subject = "Test"
ms.Body = "Test Message"
Dim mattach As New MailAttachment("c:\temp\temp.pdf")
ms.Attachments.Add(mattach)
SmtpMail.Send(ms)

The pdf file is 16453 bytes. If retrieved via a browser, then view/saved it
is still 16453 bytes. If the exact same file is emailed as an attachment
using the above code, the attachment is one byte less at 16452 bytes.
Acrobat considers it a corrupt file and won't open it. Other pdf files do
not have this problem when emailed. I suspect the problem has nothing to do
with pdf files, but that some attachments are just clipped by 1 byte.

If I email the exact same file using an email program, the file is not
clipped by one byte.

Anyone seen this, have a workaround, or suggestions?

Thanks
Russ Stevens
Nov 20 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
it's probably to do w/ the encoding type. try setting to either binary or
utf-8.

see if that helps.

steve

"Russell Stevens" <ra*******@aol.com> wrote in message
news:eG**************@TK2MSFTNGP09.phx.gbl...
| I generate pdf files on my server and allow users to access them via a
| browser and also email them. Most files work fine whether the user uses
his
| browser or gets an email with a pdf attachment which he can then open with
| Acrobat. All my pdf files work fine via a browser, but some are corrupted
| by one byte when sent as an email attachment. The problem is 100%
| reproducible - the code is trivial. Am I missing something obvious or is
| this a bug with SmtpMail. ie
|
| Imports System.Web.Mail
|
| Dim ms As New MailMessage
| ms.To = "so*******@someplace.com"
| ms.From = "so*****@somewhere.com"
| ms.BodyFormat = MailFormat.Text
| ms.Subject = "Test"
| ms.Body = "Test Message"
| Dim mattach As New MailAttachment("c:\temp\temp.pdf")
| ms.Attachments.Add(mattach)
| SmtpMail.Send(ms)
|
| The pdf file is 16453 bytes. If retrieved via a browser, then view/saved
it
| is still 16453 bytes. If the exact same file is emailed as an attachment
| using the above code, the attachment is one byte less at 16452 bytes.
| Acrobat considers it a corrupt file and won't open it. Other pdf files do
| not have this problem when emailed. I suspect the problem has nothing to
do
| with pdf files, but that some attachments are just clipped by 1 byte.
|
| If I email the exact same file using an email program, the file is not
| clipped by one byte.
|
| Anyone seen this, have a workaround, or suggestions?
|
| Thanks
| Russ Stevens
|
|
Nov 20 '05 #2

P: n/a
<<it's probably to do w/ the encoding type. try setting to either binary or
utf-8.>>

Steve,

There are only two choices,

MailEncoding.Base64
MailEncoding.UUEncode

Neither one of them work.

Thanks
Russ Stevens

Nov 20 '05 #3

P: n/a
Steve,

Well, I guess I hadn't tried both choices. I had tried MailEncoding.Base64
and that did not work. I did not bother to specifically try
MailEncoding.UUEncode as the Micorosft Docs cleary state that
MailEncoding.UUEncode is the default when you don't specify an encoding.

So - it appears the Docs are wrong and in addition, why would Microsoft
pick a default that doesn't work.

Geesh.

Thanks
Russ Stevens

Nov 20 '05 #4

P: n/a
they picked uuencode b/c it was the first format for attachments...and it is
recognized by all email clients that support the receipt thereof. not all
clients support base64...but it is quickly becoming the default for the
clients' attachment encoding style. the choice is logical and formal and has
no association as to the functionality of the object's interface...there is
either an error in their code or an error in yours. i think theirs has been
tested a bit more and would have been patched by now if for some reason it
went un-detected...don't be so fast to throw stones.

code snippets help a lot in here.

steve

"Russell Stevens" <ra*******@aol.com> wrote in message
news:eo**************@tk2msftngp13.phx.gbl...
| Steve,
|
| Well, I guess I hadn't tried both choices. I had tried
MailEncoding.Base64
| and that did not work. I did not bother to specifically try
| MailEncoding.UUEncode as the Micorosft Docs cleary state that
| MailEncoding.UUEncode is the default when you don't specify an encoding.
|
| So - it appears the Docs are wrong and in addition, why would Microsoft
| pick a default that doesn't work.
|
| Geesh.
|
| Thanks
| Russ Stevens
|
|
|
Nov 20 '05 #5

P: n/a
<<code snippets help a lot in here>>

Not quite sure what you mean by that remark - I included the entire snippet.

<<there is either an error in their code or an error in yours. i think
theirs has been
tested a bit more and would have been patched by now if for some reason it
went un-detected.>>

Really - their Internet stuff is totally buggy. Try uploading a file to a
server that has basic authentication. For every byte that is uploaded, three
bytes get sent down the wire. They have known about this problem since I
reported it when they first released .NET and have still not patched or
fixed it - upload a 1 MB file and it takes 3 MB - 100% reproducible using my
code or Microsoft's.

As far as my code being bad, it is kinda hard to have an error in a single
line of code.

Dim mattach As New MailAttachment("c:\temp\temp.pdf")

The above line does NOT work. I quote from the Microsoft docs for the
constructor;

"Initializes a new instance of the MailAttachment class with the specified
file name for the attachment. Sets the Encoding property to UUEncode by
default.
Public Sub New(String)"

If you do not specify UUEncode, then the file ends up one byte short of a
load. The following works

Dim mattach As New MailAttachment("c:\temp\temp.pdf", MailEncoding.UUEncode)

although it should be equivalent to the above according to the docs. The
following does NOT work

Dim mattach As New MailAttachment("c:\temp\temp.pdf", MailEncoding.Base64)

It would appear to me that the default is probably MailEncoding.Base64 but
that doesn't seem logical because the default is typically the enum with a
value of 0 which is MailEncoding.UUEncode. The bottom line is that unless
you specify UUEncode (which is supposed to be the default) it doesn't work.
But it is not that simple either. It works "most of the time" if you don't
specify UUEncode (just use the default). It seems to work when sending 100s
of emails with attachments. Seems to have problems when only sending 1
email. I have not been able to determine a pattern. ie - the identical line
of code, identical file, sometimes works, sometimes doesn't, but if you
specify UUEncode, it seems to work all the time.

Russ Stevens
Nov 20 '05 #6

P: n/a
Hi Russel,

Based on my understanding, you are using SmtpMail send email with an pdf
attachment, just one of the pdf files has problem(one byte clipped)
I wonder this may be caused by the smtpserver setting.
You may try to take a look at the link below to see if that will help you.
Periods at the Beginning of a Line Are Removed When Placed into the SMTP
Pickup Directory
http://support.microsoft.com/?id=286358

If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
Reply-To: "Russell Stevens" <ra*******@aol.com>
From: "Russell Stevens" <ra*******@aol.com>
Subject: SmtpMail Problems
Date: Mon, 10 Nov 2003 11:55:50 -0500
Lines: 36
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <eG**************@TK2MSFTNGP09.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: d32.as0.alpe.mi.voyager.net 216.93.11.33
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:155575
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I generate pdf files on my server and allow users to access them via a
browser and also email them. Most files work fine whether the user uses his
browser or gets an email with a pdf attachment which he can then open with
Acrobat. All my pdf files work fine via a browser, but some are corrupted
by one byte when sent as an email attachment. The problem is 100%
reproducible - the code is trivial. Am I missing something obvious or is
this a bug with SmtpMail. ie

Imports System.Web.Mail

Dim ms As New MailMessage
ms.To = "so*******@someplace.com"
ms.From = "so*****@somewhere.com"
ms.BodyFormat = MailFormat.Text
ms.Subject = "Test"
ms.Body = "Test Message"
Dim mattach As New MailAttachment("c:\temp\temp.pdf")
ms.Attachments.Add(mattach)
SmtpMail.Send(ms)

The pdf file is 16453 bytes. If retrieved via a browser, then view/saved it
is still 16453 bytes. If the exact same file is emailed as an attachment
using the above code, the attachment is one byte less at 16452 bytes.
Acrobat considers it a corrupt file and won't open it. Other pdf files do
not have this problem when emailed. I suspect the problem has nothing to do
with pdf files, but that some attachments are just clipped by 1 byte.

If I email the exact same file using an email program, the file is not
clipped by one byte.

Anyone seen this, have a workaround, or suggestions?

Thanks
Russ Stevens


Nov 20 '05 #7

P: n/a
Peter,

<<I wonder this may be caused by the smtpserver setting. You may try to take
a look at the link below to see if that will help you. Periods at the
Beginning of a Line Are Removed When Placed into the SMTP Pickup Directory>>

DisablePickupDotStuff - Now that is a strange, obscure setting <g>. However,
I don't think that is the problem. The pdf file doesn't start with a period
and I have the same problem on a Win2K server and my XP development box. It
also doesn't explain why using the attachment constructor with a default of
UUEncode doesn't work but specifically specifying UUEncode does work.

I also think this problem is much more widespread. I have talked to numerous
customers that kept getting corrupt email attachments. I would just have
them do a File, Properties and find that the file was missing a byte. I
always assumed that their email program was at fault. These attachments were
not sent by me, but by others. I now suspect that lots of other people are
experiencing this bug and may not know it.

If you like, I can email you a test file so that you can duplicate the
problem.

Thanks
Russ Stevens
Nov 20 '05 #8

P: n/a
Hi Russell,

Since I can not reproduce the problem, I think it is better that you can
send me a test file for me to reproduce the problem.
You may email to me by removing the online from my email address, I will
appreciate your efforts.
Another suggestion, have you tried use microsoft outlook or outlook express
to send the same attachment with the same smtp server as you use in your
code?

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #9

P: n/a
Hi Russel,

Yes, I can reproduce the problem with your attachment.
After my test, I find that the code line
Dim mattach As New MailAttachment("FullPathToTest.PDF")
will use Base64 by default. You may use the code line below to check it
after the code line above.
Console.WriteLine(mattach.Encoding.ToString())
I have reported the issue. But I can guarantee if it will be fixed in
future.

Have you try to modify the SMTP server setting according to the KB link?
Periods at the Beginning of a Line Are Removed When Placed into the SMTP
Pickup Directory
http://support.microsoft.com/?id=286358

I compare the corrupted pdf file with the well pdf file using a hexadecimal
editor, and I find the different between then is the "." (2E in
hexadecimal).

If you have any question, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
X-Tomcat-ID: 49861575
References: <eG**************@TK2MSFTNGP09.phx.gbl> <SJ**************@cpmsftngxa06.phx.gbl>
<ud*************@TK2MSFTNGP09.phx.gbl>MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: v-******@online.microsoft.com (Peter Huang)
Organization: Microsoft
Date: Wed, 12 Nov 2003 01:47:51 GMT
Subject: Re: SmtpMail Problems
X-Tomcat-NG: microsoft.public.dotnet.languages.vb
Message-ID: <nt**************@cpmsftngxa06.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
Lines: 15
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:156055
NNTP-Posting-Host: TOMCATIMPORT2 10.201.218.182

Hi Russell,

Since I can not reproduce the problem, I think it is better that you can
send me a test file for me to reproduce the problem.
You may email to me by removing the online from my email address, I will
appreciate your efforts.
Another suggestion, have you tried use microsoft outlook or outlook expressto send the same attachment with the same smtp server as you use in your
code?

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Nov 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.