Why am I getting an error saving an attachment using smtpop?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PeterPyc
    New Member
    • Sep 2010
    • 1

    Why am I getting an error saving an attachment using smtpop?

    Hi
    I'm using the GPL tool smtpop to read email from an account and save attachments to the server.

    I'm using the standard code as supplied in the help. An excerpt is shown below.

    The code reads the email OK but fails attempting to read the attachment.

    I get an error "Invalid character in Base-64 string" at
    Convert.FromBas e64String(attac h.Body);

    The file I am trying to save is an XML file which I have Encrypted using Rijndael encryption and saved with a .exml extension.
    I don't think this is related to the problem because I tried sending a simple text file and got the same error.

    When I looked at the value of attach.Body in the debugger I found that it contained "=" followed by a new line after each 74th character.
    Not sure why that would be.

    I tried using other methods to convert the string to a byte array.
    Code:
    Byte[] b = Encoding.Unicode.GetBytes(attach.Body);
    or
    Code:
    System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
    Byte[] b = encoding.GetBytes(attach.Body.Replace("=",""));
    Both these options ran without error but resulted in an output file that didn't match the input file (additional characters added).

    I'm running on a Windows XP box.
    Apart from that, any ideas what I am doing wrong.

    Thanks in advance for your help! :)

    Code:
    ...
    SmtPop.MimeAttachment attach = msg.Attachments[0];
    if (attach.Filename.Contains(".exml"))
    {
        // read data from attachment
        Byte[] b = Convert.FromBase64String (attach.Body);
        ...
Working...