Hi all,
I used to send MIME mails with attachments as follows:
#define SENDMAIL "/usr/lib/sendmail -t"
+ (void)sendMailFrom:(NSString *)from to:(NSString *)to
subject:(NSString *)subject body:(NSString *)body
attachments:(NSArray
*)attachments
{
FILE *out = popen(SENDMAIL, "w");
fprintf(out, "From: %sn", [from cString]);
fprintf(out, "To: %sn", [to cString]);
fprintf(out, "Subject: %sn", [subject
cString]);
if ([attachments count]) // MIME message
{
NSEnumerator *enumerator = [attachments
objectEnumerator];
NSDictionary *dic;
NSString *mime_boundary =
"-1747901728-1448367683-913849620=:4553";
fprintf(out, "MIME-Version: 1.0n");
fprintf(out, "Content-Type: multipart/mixed;
BOUNDARY="%s"n",
[mime_boundary cString]);
fprintf(out, "n");
// write dummy message body
fprintf(out," This message is in MIME format.
The first part
should be readable text,n");
fprintf(out," while the remaining parts are
likely unreadable
without MIME-aware tools.n");
fprintf(out," Send mail to mime docserver.cac.washington.edu for
more info.n");
fprintf(out,"n");
// write message text
fprintf(out, "--%sn", [mime_boundary
cString]);
fprintf(out, "Content-Type: text/plain;
charset=US-ASCIIn");
fprintf(out,"n");
fprintf(out, [body cString]);
fprintf(out,"n");
while (dic = [enumerator nextObject])
{
NSString *filename = [dic objectForKey: "filename"];
NSData *data = [dic objectForKey: "data"];
NSData *encodedData = [GSMimeDocument
encodeBase64:data];
fprintf(out,"--%sn", [mime_boundary
cString]);
fprintf(out,"Content-Type: %s;
name="%s"n", [[self
guessMIMEType:filename] cString], [[self basename:filename]
cString]);
fprintf(out,"Content-Transfer-Encoding:
base64n");
fprintf(out,"Content-Description:n");
fprintf(out,"n");
// mime kodierte Daten des attachments ausgeben
if (encodedData)
{
int i, length = [encodedData length];
const char *pChar = [encodedData bytes];
for (i = 0 ; i < length ; i++)
{
putc(*pChar, out);
pChar++;
}
fprintf(out,"rn");
}
}
fprintf(out, "--%s--n", [mime_boundary
cString]);
}
else
{
fprintf(out, "n");
fprintf(out, [body cString]);
}
pclose(out);
}
If I remember correctly this worked with an older version of
GNUstep
(but I could also be wrong here). I just tried that with the
latest
GNUstep release. The mail is sent (of course) but the
attachment does
not get through correctly. PDF or TIFFs or whatever cannot
be opened on
the other end. It seems that Mail.app does not do the back
conversion
from base64 to binary format. What am I missing?
Thanks a lot!
Regards,
Andreas
_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep gnu.org
http://lists.gnu.org/mailman/listinfo/discuss-gnustep
|