0

私はこのコードを使用して、何か問題が発生したときに自動エラー メッセージを送信しました。問題なく動作しますが、動作が少しおかしいです。この SO questionからコードを取得しました。

- (void)sendEmailWithMail:(NSString *) toAddress withSubject:(NSString *) subject Attachments:(NSArray *) attachments { 
NSString *bodyText = @"Your body text \n\r";    
NSString *emailString = [NSString stringWithFormat:@"\
                         tell application \"Mail\"\n\
                         set newMessage to make new outgoing message with properties {subject:\"%@\", content:\"%@\" & return} \n\
                         tell newMessage\n\
                         set visible to false\n\
                         set sender to \"%@\"\n\
                         make new to recipient at end of to recipients with properties {name:\"%@\", address:\"%@\"}\n\
                         tell content\n\
                         ",subject, bodyText, @"McAlarm alert", @"McAlarm User", toAddress ];

//add attachments to script
for (NSString *alarmPhoto in attachments) {
    emailString = [emailString stringByAppendingFormat:@"make new attachment with properties {file name:\"%@\"} at after the last paragraph\n\
                   ",alarmPhoto];

}
//finish script
emailString = [emailString stringByAppendingFormat:@"\
               end tell\n\
               send\n\
               end tell\n\
               end tell"];



//NSLog(@"%@",emailString);
NSAppleScript *emailScript = [[NSAppleScript alloc] initWithSource:emailString];
[emailScript executeAndReturnError:nil];
[emailScript release];

/* send the message */
NSLog(@"Message passed to Mail");
}

件名と本文が指定された新しいメッセージを作成して送信しますが、作成されたメッセージを開いたままにし、作成したメッセージとメール自体を手動で閉じる必要があります。

メールとそれ自体を自動的に閉じるようにメールに指示する方法についてのアイデアはありますか?

4

3 に答える 3

0

それは私の答えからのもので、私にとってはうまくいきます。コードのどこかにエラーがあると思います。変数が初期化されていないか、フォーマットが正しくない可能性がありますか?

静的な Apple Script コードを Apple Script エディタに挿入して実行し、そこで機能するかどうかを確認してください。そうでない場合は、Obj-C コードに何か問題があるはずです。

于 2012-10-31T10:50:55.533 に答える
0

このバグは、メールがその時点で開いているフルスクリーン アプリケーションである場合にのみ発生すると思いますが、ウィンドウを閉じている場合 (ただし、メールはドックでまだ実行されている場合)、作成されたメール メッセージがまだ開いていることはありません。

于 2013-04-27T01:25:24.237 に答える