我尝试了来自不同网站的2个代码,以从我的iOS应用发送电子邮件。 当我按发送按钮时,它调用方法 mailComposeController ,并且始终将我的日志发送邮件作为结果参数总是 MFMailComposeResultSent.value ,即使我的飞机模式下有我的iPhone 5S 。
I tried 2 codes from different sites to send an email from my iOS app. When I press the Send button it calls the method mailComposeController and always returns me the log "Mail sent" as the result parameter is always MFMailComposeResultSent.value, even when I have my iPhone 5S in airplane mode.
此外,甚至当我有互联网连接时,我从来没有收到电子邮件。已经检查了垃圾邮件和其他文件夹,并等待了整整一天,如果它被延迟,但从来没有收到甚至尝试几次。
Besides this, even when I have internet connection, I never receive the email. Already checked SPAM and other folders and waited one entire day if it was delayed but never received even trying several times.
我使用Swift编程,并在Macbook Pro中使用XCode 6.4视网膜从2014年年中开始,优胜美地10.10.5。
I program with Swift and use XCode 6.4 in a Macbook Pro retina from mid-2014 with Yosemite 10.10.5.
这里是Swift代码:
Here the Swift code:
import UIKit import MessageUI class ViewController: UIViewController, MFMailComposeViewControllerDelegate { override func viewDidLoad() { super.viewDidLoad() if (MFMailComposeViewController.canSendMail()) { var emailTitle = "Vea Software Feedback" var messageBody = "Vea Software! :)" var toRecipents = ["oscar.muntal@gmail"] var mc: MFMailComposeViewController = MFMailComposeViewController() mc.mailComposeDelegate = self mc.setSubject(emailTitle) mc.setMessageBody(messageBody, isHTML: false) mc.setToRecipients(toRecipents) self.presentViewController(mc, animated: true, completion: nil) }else { println("No email account found") } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } // Email Delegate func mailComposeController(controller:MFMailComposeViewController, didFinishWithResult result:MFMailComposeResult, error:NSError) { switch result.value { case MFMailComposeResultCancelled.value: println("Mail cancelled") case MFMailComposeResultSaved.value: println("Mail saved") case MFMailComposeResultSent.value: println("Mail sent") case MFMailComposeResultFailed.value: println("Mail sent failure: \(error.localizedDescription)") default: break } self.dismissViewControllerAnimated(false, completion: nil) } }非常感谢您的帮助。
推荐答案以下代码工作正常:
import UIKit import MessageUI class ViewController: UIViewController, MFMailComposeViewControllerDelegate { override func viewDidLoad() { super.viewDidLoad() if MFMailComposeViewController.canSendMail() { let toRecipents = ["oscar.muntal@gmail"] let emailTitle = "Vea Software Feedback" let messageBody = "Vea Software! :)" let mc: MFMailComposeViewController = MFMailComposeViewController() mc.mailComposeDelegate = self mc.setToRecipients(toRecipents) mc.setSubject(emailTitle) mc.setMessageBody(messageBody, isHTML: false) presentViewController(mc, animated: true, completion: nil) } else { print("cannot send mails") } } func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) { switch result { case MFMailComposeResultCancelled: print("Mail cancelled") case MFMailComposeResultSaved: print("Mail saved") case MFMailComposeResultSent: print("Mail sent") case MFMailComposeResultFailed: print("Mail sent failure: \(error?.localizedDescription)") default: break } dismissViewControllerAnimated(true, completion: nil) } }更多推荐
试图从应用程序发送电子邮件,不起作用
发布评论