Let's say you want to send a simple text file (details.txt) as an attachment. You could use this:
Code:
// send these:
// HELO
// MAIL FROM:
// RCPT TO:
// DATA
// now send MIME-version
sprintf( buf, "MIME-Version: 1.0" );
send( socket, buf );
// Send the Content-Type: multipart/mixed;
sprintf( buf, "Content-Type: multipart/mixed;" );
send( socket, buf );
// send the Content-Transfer-Encoding: quoted-printable
sprintf( buf, "Content-Transfer-Encoding: quoted-printable" );
send( socket, buf );
// send the Content-Type: text/plain;
sprintf( buf, "Content-Type: text/plain;" );
send( socket, buf );
// send the name="details.txt"
sprintf( buf, " name=\"details.txt\" " );
send( socket, buf);
// send the Content-Disposition: attachment;
sprintf( buf, "Content-Disposition: attachment;" );
send( socket, buf);
// send a blank line first !
sprintf( buf, "\r\n" );
send( socket, buf);
// now, get the attachment contents and send them
// line by line.
MailFilePtr = fopen( AttachmentFile, "r" );
if ( MailFilePtr == NULL )
{
// handle error
}
memset( FileBuffer, 0, sizeof(FileBuffer) );
while ( fgets (FileBuffer, sizeof( FileBuffer), MailFilePtr) )
{
sprintf( buf, "%s", FileBuffer );
buf[strlen(buf)- 1] = 0;
send( socket, buf );
memset( FileBuffer, 0, sizeof(FileBuffer) );
memset( buf, 0, sizeof(buf) );
}
fclose( MailFilePtr );
sprintf( buf, "\r\n");
send( socket, buf );
This should work. Hope this helps.