Hello all,
Am writing an small basic e-mail client and i'm having difficulty
encoding images to Base64. When i send an attachment image with it to
Outlook Express, it seems as if it only converts a certain amount of
the image to Base64.
The message does appear as attached but doesn't render correctly and is
a much smaller filesize than the original image attached.
I seem to be only getting the first 774 bytes of an image i attach and
viewing the headers of the message seems like it didn't send all of the
Base64 encoded data.
// convert attachment to base 64
System.IO.FileStream fs = new System.IO.FileStream(txtAttachment.Text,
System.IO.FileMode.Open);
byte[] by = new byte [fs.Length];
long bytesRead = fs.Read(by, 0, (int)fs.Length);
fs.Close();
string bytes2 = System.Convert.ToBase64String((by), 0, by.Length);
Data+= bytes2 + CRLF + CRLF;
Data+= "--" + uniqueIDContID + "--" + CRLF;
Data+= CRLF + "." + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArr ay());
NetStrm.Write(szData,0,szData.Length) ;
Note:
txtAttachment.Text is the location of the file (e.g
"C:\images\image001.jpeg")
uniqueIDContID is the unique boundary generated for a multipart
message.
CRLF is just a character return ("\r\n")
I DO issue the "QUIT" command to the server after that block of code..
i just didn't think it was necessary to include it.
Anyone got any suggestions as to where i'm going wrong?
Many thanks in advance.