【问题标题】:MFMailComposeViewController canSendMail returns YES but not sending mail in iOSMFMailComposeViewController canSendMail 返回 YES 但不在 iOS 中发送邮件
【发布时间】:2013-03-27 15:46:51
【问题描述】:

以下是我在邮件中发送附件的代码。这工作正常。我可以发送邮件,但我并不总是收到邮件。

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

// Set the subject of email
[picker setSubject:@"My data file"];

// Add email addresses

[picker setToRecipients:[NSArray arrayWithObjects:emailId, nil]];


// Fill out the email body text
NSString *emailBody = @"Hello, \n Please find the data from the iOS app in the attachments.\n\n Thank you.\nMy Team.";

// This is not an HTML formatted email
[picker setMessageBody:emailBody isHTML:NO];

// Create NSData object from file
NSData *exportFileData = [NSData dataWithContentsOfFile:filePath];

// Attach image data to the email
[picker addAttachmentData:exportFileData mimeType:@"text/csv" fileName:  [self.CSVNameTextField text]];


// Show email view

if ([MFMailComposeViewController canSendMail]) {

    [self presentModalViewController:picker animated:YES];
}

【问题讨论】:

  • 你在模拟器中测试吗?
  • 附注 - 为什么要创建邮件撰写控制器然后检查邮件是否可以发送?如果您可以发送邮件,您应该只创建控制器并进行设置。
  • 你说这段代码只在某些时候有效。然后你说你不能从应用程序发送邮件。它是哪一个?您有时可以从应用程序发送邮件,还是从不从应用程序发送邮件?
  • 我可以一直发送邮件,但收不到邮件。我有时会收到邮件。
  • 我已经更改了我的问题的内容,以便更清楚发生了什么

标签: ios mfmailcomposeviewcontroller mfmailcomposer


【解决方案1】:

使用您的应用程序发送邮件后,转到 iPhone 上的邮件软件,您很可能会在发件箱中找到邮件。

因为 MFMailComposeViewController 只会将邮件转发到邮件软件,它并不关心邮件旁边会发生什么。因此,发件箱的更新方式和时间取决于您的邮件软件。

【讨论】:

    【解决方案2】:

    我有同样的问题,我发现它会通过邮箱并说它已发送,然后什么都不会通过。

    大约 20-30 分钟后,第一个通过了,然后我发送的其余部分也逐渐通过了。

    我不知道为什么要花这么长时间,如果我发现我会编辑这个答案,但肯定要等上一个小时才能假设你的代码被破坏了。

    希望这对像我一样可能一遍又一遍地搜索他们的代码的人有所帮助

    【讨论】:

    • 您有没有找到更持久的解决方案?我也遇到了这个问题。电子邮件排队,但(有时)未发送。
    【解决方案3】:

    在我的情况下,我必须手动打开 iphone 邮件应用程序,然后立即发送和接收邮件。

    【讨论】:

    • 这应该是一条评论
    猜你喜欢
    • 2019-06-18
    • 1970-01-01
    • 2011-01-29
    • 2011-03-24
    • 2015-11-19
    • 1970-01-01
    • 2016-11-18
    • 2010-12-04
    • 2012-08-17
    相关资源
    最近更新 更多