Menu

Attachment problem

eusebiu
2006-02-03
2013-04-02
  • eusebiu

    eusebiu - 2006-02-03

    hello...

    Let`s say that we have the following C# code :

    using(MemoryStream imageStream = new MemoryStream())
                {
                    //create a bitmap image
                    Bitmap b = graphBuilder.BuildImageGraph(...);
                    b.Save(imageStream,System.Drawing.Imaging.ImageFormat.Jpeg);
                   
                    EmailMessage emailMessage = new EmailMessage();
                    //email details
                    //...
                    FileAttachment relatedFileAttachment = new FileAttachment(imageStream.GetBuffer(), "a1");
                    emailMessage.AddRelatedAttachment( relatedFileAttachment );
                   
                    SmtpServer s = new SmtpServer("localhost");
                }

    When I verify my e-mail , i get only a part of the image.

    Can you tell me why I get this?

     
    • eusebiu

      eusebiu - 2006-02-04

      Hello...After I`ve read some of the threads , I found that my problem was solved by 'jatubio' in his thread : Corrupts Attachement!!!

      ...
      int charstoread=Base64Encoder.MAX_CHARS_PER_LINE * 100;

      This is a problem because the base64 conversion works on groups of 3 bytes (7600 / 3 isn't an integer number!), so you get a different results than converting the whole array!
      A solution could be to convert the whole array all at once or to use a block size divisible by 3 (e.g. 76 * 102)

      ...

      I`ve downloaded the sources and changed 100 with 102 and now it`s waorking!

      See ya!

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.