iPhone使用MFMailComposer从应用程序发送电子邮件?

时间:2012-06-07 07:43:51

标签: iphone ios xcode ios4 mfmailcomposeviewcontroller

在我的应用程序中,我可以使用MFMailComposer发送电子邮件。 假设我的iPhone中有gmail帐户并且我正在使用我的应用程序发送电子邮件,我可以向其他人发送电子邮件

但是假设我的iPhone中有雅虎帐户并且我使用我的应用程序发送电子邮件,我无法发送电子邮件。

我真的不知道是什么问题,MFMailComposer仅使用gmail帐户或m代码有什么问题。

请帮帮我。

以下是我的代码:

-(void)SENDEMAIL
{
    if ([MFMailComposeViewController canSendMail]) 
    { 
        MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init]; 
        mailComposer.mailComposeDelegate = self; 
        NSArray* arr = [[dictUser valueForKey:@"recipients"] componentsSeparatedByString:@","];
        NSLog(@"mailcomporeci%@",dictUser);
        NSLog(@"arr:%@",arr);
        [mailComposer setToRecipients:arr]; 

        //[mailComposer setSubject:[NSString stringWithFormat:@"Scheduled Email %@",arr]];
        [mailComposer setSubject:@"Scheduled Email"];
        [mailComposer setMessageBody:[dictUser objectForKey:@"message"] isHTML:NO];
        mailComposer.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        [self.tabBarController presentModalViewController:mailComposer animated:YES]; 
        [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(hackMail:) userInfo:mailComposer repeats:NO];
         }
     }

-(void)hackMail:(NSTimer*)theTimer {
    MFMailComposeViewController *mailController = theTimer.userInfo;
    UIBarButtonItem *sendBtn = mailController.navigationBar.topItem.rightBarButtonItem;
    id targ = sendBtn.target;
    [targ performSelector:sendBtn.action withObject:sendBtn];
}

#pragma mark Mail Compose Delegate Methods 
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {  

    switch (result) 
    { 
        case MFMailComposeResultCancelled: 
        {
            break; 
        }
        case MFMailComposeResultSaved: 
        {
            break; 
        }
        case MFMailComposeResultSent:
        {
            break; 
        }
        case MFMailComposeResultFailed: {  

            break; 
        } 

        default:  
            break; 
    } 

    [self.tabBarController dismissModalViewControllerAnimated:YES];
}

1 个答案:

答案 0 :(得分:1)

尝试并查看结果:

if([MFMailComposeViewController canSendMail]){

[self presentModalViewController:mailController animated:YES];

}

可能是您的设备未配置为任何帐户发送邮件。