Quote Originally Posted by marcel View Post
This is what I was asking.
If you encode the data to base 64 before sending it.
Also, I asked if you tested this base 64 encoding/decoding locally.
Maybe you don't decode from base64 ok.
Regards
The decoding from base64 is taken care by smtp once I use
Content-Transfer-Encoding: base64
after the DATA tag used for smtp.

I imagine you cannot post the code, but are you sure there aren't any differences between plain files? Not even a byte?
Do you handle well SMTP transparency and the end of data message indicator?
Because a plain file might work even if you miss a byte, but an encoded file won't.
I can here is the small sample
Qt Code:
  1. void SynsupMail::sendMessage()
  2. {
  3. QString message;
  4. string msg;
  5.  
  6. QFile f ( textFilename->text() ); //textFilename->text() contains file path. The file can be en
  7. //encrypted using AES::CBC or a plain text
  8. if ( f.open (IO_ReadOnly) )
  9. {
  10. // file opened successfully
  11. QTextStream t ( &f );
  12. // read the contents of the file into message
  13. while( ! t.eof() )
  14. {
  15. message += t.readLine();
  16. message += "\n";
  17. }
  18. f.close();
  19.  
  20. //encode the data using base64 using crypto++ library for Qt3, in Qt4
  21. //there is a function tobase64().
  22. StringSource (string(message.data()), true, new Base64Encoder(new StringSink(msg))) ;
  23.  
  24. Smtp *smtp = new Smtp( textFrom->text(), textTo->text(), textSubject->text(),
  25. QString(msg.data()), fileName, );
  26. }
  27. }
To copy to clipboard, switch view to plain text mode 
All the code in smtp.cpp is same as that of /examples/network/mail except this
else if in function void Smtp::readyRead(). I made this modification to
send the file as an attachment
Qt Code:
  1. else if ( state == Body && responseLine[0] == '3' )
  2. {
  3. QString fileName("");
  4. QString version;
  5. version += QString("MIME-Version: 1.0\r\n");
  6.  
  7. QString Header;
  8. Header += QString("Content-Type: multipart/mixed; ") +
  9. QString("boundary=unique-boundary-1\r\n") ;
  10.  
  11. QString headerContent;
  12. headerContent += QString("--unique-boundary-1\r\n");
  13. headerContent += QString("Content-Type: application/octet-stream ") + QString("\r\n");
  14.  
  15. headerContent += QString("Content-Transfer-Encoding: base64\r\n");
  16. headerContent += QString("Content-Disposition: attachment;") +
  17. QString( "filename=" ) + _fileName ;
  18.  
  19. //t is QTextStream
  20. *t << version;
  21. *t << address;
  22. *t << Header;
  23. *t << headerContent;
  24.  
  25. *t << message;
  26. QString closeTag;
  27. closeTag += QString("--unique-boundary-1--\r\n");
  28.  
  29. *t << closeTag << ".\r\n";
  30. state = Quit;
  31. }
To copy to clipboard, switch view to plain text mode 
These are the things that happen,
Plain text file--->
plaintext file --> Encoding base64 --> Over N/w --> SMTP decodes base64 --> plaintext file to receiver
Encrypted file (encrypted with AES::CBC)--->
Encrypted file --> Encoding base64 --> Over N/w --> SMTP decodes base64 --> Encrypted file
M i doing anything wrong above ?