C
Cristiano
Hello,
I'm trying to send as an attachment a zip file, in my C++ application.
To send using SMTP protocol, I'm trying to cripting the zip file to
base64 code.
I'm using this code to convert: http://www.adp-gmbh.ch/cpp/common/base64.html
The code convert the zip file in base64 code and I can send the e-
Mail.
But, when I receive the e-Mail, I download the zip file and when I try
to open it, I have a error mesage "the zip file is corrupted".
I got this error just using zip files. Whan I attach text files, this
erros doesn't exists.
Please, can you help me with this?
I'm converting the zip file like this:
============================================================
string copyFileToString(string filename)
{
string retorno;
FILE *from;
from = fopen (filename.c_str(),"rb");
char ch;
/* copy the file */
while(!feof(from))
{
ch = fgetc(from);
if(ferror(from))
{
//printf("Error reading source file.\n");
exit(1);
}
if(!feof(from))
retorno += ch;
}
if(fclose(from)==EOF)
{
//printf("Error closing source file.\n");
exit(1);
}
return retorno;
}
//...
int main()
{
//...
string file = copyFileToString("sample.zip");
string fileBase64 = base64_encode(reinterpret_cast<const unsigned
char*>(file.c_str()), file.length());
//...
}
============================================================
So, am I doing some mistake ?
Thank you.
I'm trying to send as an attachment a zip file, in my C++ application.
To send using SMTP protocol, I'm trying to cripting the zip file to
base64 code.
I'm using this code to convert: http://www.adp-gmbh.ch/cpp/common/base64.html
The code convert the zip file in base64 code and I can send the e-
Mail.
But, when I receive the e-Mail, I download the zip file and when I try
to open it, I have a error mesage "the zip file is corrupted".
I got this error just using zip files. Whan I attach text files, this
erros doesn't exists.
Please, can you help me with this?
I'm converting the zip file like this:
============================================================
string copyFileToString(string filename)
{
string retorno;
FILE *from;
from = fopen (filename.c_str(),"rb");
char ch;
/* copy the file */
while(!feof(from))
{
ch = fgetc(from);
if(ferror(from))
{
//printf("Error reading source file.\n");
exit(1);
}
if(!feof(from))
retorno += ch;
}
if(fclose(from)==EOF)
{
//printf("Error closing source file.\n");
exit(1);
}
return retorno;
}
//...
int main()
{
//...
string file = copyFileToString("sample.zip");
string fileBase64 = base64_encode(reinterpret_cast<const unsigned
char*>(file.c_str()), file.length());
//...
}
============================================================
So, am I doing some mistake ?
Thank you.