Pripyat
Pripyat

Reputation: 2937

Sending an E-Mail with attachments in Cocoa

I have an NSTextView with text & images in it, which is supposed to send both in an e-mail.I know that the message.framework is deprecated,so I came up with the idea to send it via NSTask, since mail is integrated.I came up with the code below, however in the log I get this:

*** -[NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: _NSTaskInputFileHandle)

This is the code I am using:

NSError *error;
    if([textView writeRTFDToFile:@"/Library/Application Support/log.rtfd" atomically:NO])
    {
        NSArray *args = [NSArray arrayWithObjects:@"-s", [subject stringValue], [sendto stringValue], nil];

        NSTask *task = [[[NSTask alloc] init] autorelease];
        [task setLaunchPath:@"/usr/bin/mailx"];
        [task setArguments:args];
        [task setStandardInput:[NSFileHandle fileHandleForReadingAtPath:@"/Library/Application Support/log.rtfd"]];
        [task launch];
        [task waitUntilExit];

Can someone tell me what I am doing wrong?

Upvotes: 0

Views: 1591

Answers (1)

diederikh
diederikh

Reputation: 25271

You can also try the Scripting Bridge. See Apple's SBSendEmail example.

Upvotes: 1

Related Questions