2012-06-07 127 views
0

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

但假设如果我在我的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]; 
} 
+0

你得到的错误是什么? – Shri

+0

有没有错误,但电子邮件不是从我的雅虎帐户发送 –

+0

您可以使用默认邮件应用程序从您的雅虎帐户发送邮件吗?没有理由MFMailVomposer会为一个帐户而不是另一个帐户工作,除非它是失败的帐户。 – Jeremy1026

回答

1

试试吧,看看结果:

if([MFMailComposeViewController canSendMail]){

[self presentModalViewController:mailController animated:YES];

}

可能是你的设备没有配置以任何帐号发送邮件。

+0

如果我的iPhone设备中添加了gmail帐户,我可以从m app发送电子邮件,但是如果我在设备中添加了雅虎帐户,我无法从应用发送电子邮件。 –

+1

可能是因为,你将不得不在yahoo和gmail中设置邮件账户凭证。在设备上进行设置,你会发现邮件,联系人,日历。在那去转到添加帐户和配置你想要的任何帐户(在你的情况下雅虎和Gmail都)。 –

相关问题