2012-06-07 78 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都)。 –

相關問題