Sending an E-Mail with attachments in Cocoa

北慕城南 提交于 2019-12-06 15:04:07

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/2313006/sending-an-e-mail-with-attachments-in-cocoa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!