2

私はmessageUIFrameworkを介してMFMailComposeViewControllerを使用しました。自分宛にメールを送信しなければならない場合があります。「差出人」アドレスMFMailComposeViewControllerデリゲートを追加するにはどうすればよいですか?助言がありますか?

4

2 に答える 2

7

APPでメールを送信する方法は?

- (IBAction)sendMail:(id)sender {
    if ([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];

        mailer.mailComposeDelegate = self;

        [mailer setSubject:@"Message Pro"];

        //Destination adress
        NSArray *toRecipients = [NSArray arrayWithObjects:@"your adress", nil];
        [mailer setToRecipients:toRecipients];

        //Attachement Object
        UIImage *myImage = [UIImage imageNamed:@"image.jpeg"];
        NSData *imageData = UIImagePNGRepresentation(myImage);
        [mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"mobiletutsImage"]; 

        //Message Body
        NSString *emailBody = @"message body";
        [mailer setMessageBody:emailBody isHTML:NO];

        [self presentModalViewController:mailer animated:YES];

        [mailer release];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
                                                        message:@"Your device doesn't support the composer sheet"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles: nil];
        [alert show];
        [alert release];
    }
}

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved: you saved the email message in the drafts folder.");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");
            break;
        default:
            NSLog(@"Mail not sent.");
            break;
    }

    // Remove the mail view
    [self dismissModalViewControllerAnimated:YES];
}

忘れないでください

  1. IBAction=sendMailでボタンを追加するには
  2. MessageUI.frameworkをインポートするには
  3. .hファイルにデリゲートを追加しますMFMailComposeViewControllerDelegate
于 2012-07-23T09:33:13.940 に答える
0

「差出人」アドレスは、によって指定されますMFMailComposeViewController(ユーザーは、作成メールビューを取得するときに、構成されたメールアカウントのいずれかにオーバーライドできます)。プログラマーであるあなたは、「from」アドレスの取得/設定について心配する必要はありません。

于 2012-07-23T06:46:25.983 に答える