试图从应用程序发送电子邮件,不起作用

编程入门 行业动态 更新时间:2024-10-24 23:17:51
本文介绍了试图从应用程序发送电子邮件,不起作用 - Swift(iOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试了来自不同网站的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) } }

更多推荐

试图从应用程序发送电子邮件,不起作用

本文发布于:2023-10-13 00:19:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1486277.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   不起作用   发送电子邮件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!