【问题标题】:iPhone to use MFMailComposer to send email from app?iPhone 使用 MFMailComposer 从应用程序发送电子邮件?
【发布时间】:2012-06-07 07:43:50
【问题描述】:

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

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

我真的不知道是什么问题,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];
}

【问题讨论】:

  • 您遇到了什么错误?
  • 没有错误,但电子邮件不是从我的雅虎帐户发送的
  • 您可以使用默认邮件应用从您的雅虎帐户发送邮件吗? MFMailVomposer 没有理由对一个帐户起作用,而对另一个帐户不起作用,除非是失败的帐户。

标签: iphone ios xcode ios4 mfmailcomposeviewcontroller


【解决方案1】:

试试看结果:

if([MFMailComposeViewController canSendMail]){

[self presentModalViewController:mailController animated:YES];

}

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

【讨论】:

  • 如果我在我的 iPhone 设备中添加了 gmail 帐户,我可以从 m 应用程序发送电子邮件,但如果我在我的设备中添加了 yahoo 帐户,我将无法从应用程序发送电子邮件。跨度>
  • 可能是因为,您必须在 yahoo 和 gmail 中设置邮件帐户凭据。在设备中转到设置,您会找到邮件、联系人、日历。在那个去添加帐户并配置你想要的任何帐户(在你的情况下是雅虎和gmail)。
猜你喜欢
  • 1970-01-01
  • 2011-05-08
  • 2010-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多